jQuery ajax()vs get()/ post()

编程入门 行业动态 更新时间:2024-10-10 05:27:09
本文介绍了jQuery ajax()vs get()/ post()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

假设我想执行PHP脚本。哪种方式更好?

Let's say I want to execute a PHP script. Which way is better?

这个:

$.ajax({ type: "GET", url: "php-script.php", dataType: "script" });

或者这个:

$.get("php-script.php", function(data) { });

推荐答案

在这种情况下,我会说 $。get ,因为它会立即清楚请求的类型。无论如何,它只是更大和更多选择性的ajax调用的简写,在最坏的情况下,在两者之间进行转换是微不足道的。

In this case, I'd say $.get, as it's immediately clear what the type of request is. At any rate, it's just shorthand for the larger and more option-ified ajax call, and converting between the two is trivial in the worst case.

如果你认为你我需要花哨的 $。ajax 选项,使用 $ .ajax 。如果您不使用jQuery提供的便捷方法,例如 .load , $。get 等。

If you think that you'll need fancy $.ajax options, use $.ajax. If you don't use the convenience methods jQuery provides, such as .load, $.get, etc.

更多推荐

jQuery ajax()vs get()/ post()

本文发布于:2023-10-10 22:00:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479878.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:jQuery   ajax   post

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!