gpt4 book ai didi

javascript - jQuery AJAX : Posting serialized form data with $. post() 没有达到与 $.ajax() 相同的结果

转载 作者:行者123 更新时间:2023-12-03 09:32:18 24 4
gpt4 key购买 nike

我试图通过使用 jQuery 的速记方法 jQuery.post() 发送表单数据来将数据发布到源中,但我无法获得与使用完整蓝图相同的结果使用jQuery.ajax()发布。

请在下面找到我用于调查结果的脚本:

使用$.post():

jQuery.post(
"/full-path-to-service",
{ cache: false,
data: jQuery(submittingForm).serialize(),
_: jQuery.now() },
null,
"json"
).done(function(data) {
// Response handling
});

使用 $.ajax():

jQuery.ajax({
type: "POST",
url: "/full-path-to-service",
data: jQuery(submittingForm).serialize(),
dataType: "json",
_: jQuery.now()
}).done(function(data) {
// Response handling
});

虽然我能够从服务器收到成功的响应,但该服务似乎并未因未收到之前在 POST 请求中序列化发送的信息而被解雇。

嗅探发送到服务的信息,我能够确认在使用 jQuery.post 时信息解析不正确。

请找出以下差异:

enter image description here

是否有任何缓解 jQuery.post() 不以与使用 jQuery.ajax() 发布蓝图相同的方式发送信息的情况?

最佳答案

post() 的第二个参数是您希望传递的数据对象(或字符串)。您正尝试向其传递 ajax() 的配置对象。

post() 不是 ajax() 并且不支持相同级别的自定义。它的设计要简单得多。如果您想设置所有选项,请使用ajax()

Is there any reasing for jQuery.post() not sending the information in the same way as using a blue-print for posting with jQuery.ajax()?

是的。这是常见用例的简单简写。

关于javascript - jQuery AJAX : Posting serialized form data with $. post() 没有达到与 $.ajax() 相同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31466417/

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