mimic mimic - 1 month ago 10
Ajax Question

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",
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

Answer

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 setting jQuery.ajaxSettings.traditional = true;.