gpt4 book ai didi

javascript - 使用 Jquery AJAX 和 ASPX 表单的 POST 参数

转载 作者:行者123 更新时间:2023-11-30 10:25:38 24 4
gpt4 key购买 nike

我正在尝试将 Ajax post 发送到 ASPX 页面,虽然这个完全相同的过程适用于经典 ASP,但当 POST 到 ASPX 页面时,我的 Request.Form 对象是空的。

这是我的 Ajax 调用(我正在使用 ajaxSetup 设置 URL、编码等):

$.ajax({
data: '{"Command":"GetGeoLocations"}',
success: function (responseData) {
alert("Success " + responseData);
},
error: function (jqXHR, textStatus, errorThrown) {
alert( "The following error occured: "+
textStatus, errorThrown);
}
});

这是 ajaxSetup:

$.ajaxSetup({
url: "Ajax/AjaxForm.aspx",
datatype: "json",
contentType: "application/json; charset=utf-8",
type: "POST"
});

这是 Firebug 的 POST 参数: enter image description here

这是 .NET 端的 Request.Form 对象:

enter image description here

最佳答案

试试这个,你有额外的数据属性引号。

$.ajax({
data: {"Command":"GetGeoLocations"},
success: function (responseData) {
alert("Success " + responseData);
},
error: function (jqXHR, textStatus, errorThrown) {
alert( "The following error occured: "+
textStatus, errorThrown);
}
});

dataType T 应该是大写,

$.ajaxSetup({
url: "Ajax/AjaxForm.aspx",
dataType: "json",
contentType: "application/json; charset=utf-8",
type: "POST"
});

希望对你有帮助,谢谢

关于javascript - 使用 Jquery AJAX 和 ASPX 表单的 POST 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19688249/

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