简体   繁体   English

使用Jquery AJAX和ASPX Form的POST参数

[英]POST parameters with Jquery AJAX and ASPX Form

I am trying to send an Ajax post to an ASPX page and although this exact same process works with classic ASP, my Request.Form object is empty when POSTing to an ASPX page. 我试图将一个Ajax帖子发送到ASPX页面,虽然这个完全相同的过程适用于经典的ASP,但是当POST到ASPX页面时,我的Request.Form对象是空的。

Here is my Ajax call (I am using ajaxSetup to set URL, encoding, etc): 这是我的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);
        }
    });

Here is that ajaxSetup: 这是ajaxSetup:

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

Here is Firebug's POST parameter: 这是Firebug的POST参数: 在此输入图像描述

Here is the Request.Form object on the .NET side: 这是.NET端的Request.Form对象:

在此输入图像描述

Try this, you have extra quotes for data attribute. 试试这个,你有数据属性的额外引号。

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

dataType T should be capital, dataType T应该是资本,

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

Hope this helps, thank you 希望这有帮助,谢谢

尝试使用JSON.stringify

data: JSON.stringify({"Command":"GetGeoLocations"})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM