jQuery.Ajax makes the wrong request with array data
I have the following array:
var idParam = ["1","2","3"];
I want to send this data as request using jQuery.ajax
, what I'm doing:
$.ajax({
type: "GET",
开发者_Python百科 url: "Services/GetInfo.ashx",
data: { "id": idParam },
contentType: "application/text",
dataType: "json",
success: function(result)
{
...
},
error: function(XMLHttpRequest, textStatus, errorThrown)
{
...
}
});
But as result I have the following ugly string: ?id[]=1&id[]=2&id[]=4
(actually it's much uglier: id%5B%5D=1&id%5B%5D=2&id%5B%5D=4
).
What to do to get the normal string like: id=1&id=2&id=4
??
Thanks
I'm assuming this is with jQuery 1.4 - You need to use the traditional: true
parameter for $.ajax()
Or you can set it globally: (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 settingjQuery.ajaxSettings.traditional = true;
.
精彩评论