I'm doing a simple AJAX post using jQuery, works great:
var parameters = {firstName: 'John', lastName: 'Smith'};
$.post('http://api.example.com/rest', parameters, function(data) {
  alert('Response: ' + data.someResult);
});
However, when I add an array to the parameters like so:
var parameters = {firstName: 'John', lastName: 'Smith', children: ['Susy', 'Billy']};
Then the problem is the parameter name children gets changed to children[] (it's actually URL encoded to children%5B%5D) when POSTing to the server.  I can't change the server to look for parameters with the name children[] so what do I do?  How can I POST multiple values with the name children?  Why is jQuery changing the name of my parameter?
I believe you need to enable traditional parameter encoding.
See http://api.jquery.com/jQuery.ajax/ and http://api.jquery.com/jQuery.param
As $.post doesn't have a specific option for this you'll either need to revert to $.ajax or use the global setting jQuery.ajaxSettings.traditional = true.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With