当前位置 : 主页 > 网页制作 > JQuery >

jQuery.Ajax使用数组数据发出错误的请求

来源:互联网 收集:自由互联 发布时间:2021-06-15
我有以下数组: var idParam = ["1","2","3"]; 我想使用jQuery.ajax将此数据作为请求发送,我正在做什么: $.ajax({ type: "GET", url: "Services/GetInfo.ashx", data: { "id": idParam }, contentType: "application/text", dat
我有以下数组:

var idParam = ["1","2","3"];

我想使用jQuery.ajax将此数据作为请求发送,我正在做什么:

$.ajax({
        type: "GET",
        url: "Services/GetInfo.ashx",
        data: { "id": idParam },
        contentType: "application/text",
        dataType: "json",
        success: function(result)
        {
...
        },
        error: function(XMLHttpRequest, textStatus, errorThrown)
        {
            ...
        }
});

但结果我有以下丑陋的字符串:?id [] = 1& id [] = 2& id [] = 4(实际上它更加丑陋:id [] = 1& id [] = 2& id [] = 4).

怎么做才能得到正常的字符串:id = 1& id = 2& id = 4 ??
谢谢

我假设这是使用jQuery 1.4 – 你需要使用传统: $.ajax()的true参数

或者您可以在全球范围内进行设置:(from $.param() docs)

As of jQuery 1.4, the $.param() method serializes deep objects recursively to accommodate modern scripting languages and frameworks such as PHP and Ruby on Rails. You can disable this functionality globally by setting jQuery.ajaxSettings.traditional = true;.

网友评论