Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing arrays in ajax call using jQuery 1.4
    text
    copied!<p>The following code works for me using jQuery 1.2.6 but causes a broker error in 1.4.</p> <pre><code>var items = new Array(); items[0] = "Item 1"; items[1] = "Item 2"; items[2] = "Item 3"; var dataToSend = {'_service' : myService, '_program' : myProgram, 'selections' : items} ; $.ajax({ type: "post", url: myURL, dataType: "text", data: dataToSend, success: function(request) {$('#results').html(request); } // End success }); // End ajax method </code></pre> <p>The broker error I get indicates that what is being passed in selections is 'selections[]' </p> <p>ERROR:<em>(Invalid character "[" in field name "selections[]". This character is not allowed in field names.)</em></p> <p>Was there a change in how jQuery handles arrays in an ajax call? or was this an incorrect way to pass an array?</p> <p>Any help would be appreciated.</p> <p>EDIT: The answer from @jvenema solved my problem. With the "traditional" setting you can cause jQuery to handle the parameters like the previous version. Here are some additional links which talk about the change <a href="http://api.jquery.com/jQuery.ajax/" rel="noreferrer">jQuery.ajax()</a>, <a href="http://api.jquery.com/jQuery.param/" rel="noreferrer">jQuery.param()</a> and a blog post <a href="http://benalman.com/news/2009/12/jquery-14-param-demystified/" rel="noreferrer">jQuery 1.4 $.param demystified</a>.</p> <p>Either a general statement of </p> <pre><code>jQuery.ajaxSettings.traditional = true; </code></pre> <p>or as an additional option in the ajax call</p> <pre><code>$.ajax({ traditional: true, type: "post", url: myURL, dataType: "text", data: dataToSend, success: function(request) { $('#results').html(request); } // End success }); // End ajax method </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload