使用Jquery AJAX和ASPX Form的POST参数

时间:2013-10-30 16:17:08

标签: javascript jquery asp.net ajax

我正在尝试将一个Ajax帖子发送到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

2 个答案:

答案 0 :(得分:3)

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

$.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"
        });

希望这有帮助,谢谢

答案 1 :(得分:1)

尝试使用JSON.stringify

data: JSON.stringify({"Command":"GetGeoLocations"})
相关问题