gpt4 book ai didi

javascript - jQuery ajax() 与 get()/post()

转载 作者:IT王子 更新时间:2023-10-29 03:12:34 26 4
gpt4 key购买 nike

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

这个:

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

或者这个:

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

最佳答案

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

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

关于javascript - jQuery ajax() 与 get()/post(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1344303/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com