jQuery ajax()vs get()/ post() [英] jQuery ajax() vs get()/post()

查看:138
本文介绍了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()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆