How can I send an array to php through ajax?

Lucia picture Lucia · Nov 18, 2008 · Viewed 41.2k times · Source

I want to send an array constructed in javascript with the selected values of a multiple select. Is there a way to send this array to a php script using ajax?

Answer

Dragouf picture Dragouf · Oct 22, 2010

You might do that with $.post method of jQuery (for example) :

var myJavascriptArray = new Array('jj', 'kk', 'oo');

$.post('urltocallinajax', {'myphpvariable[]': myJavascriptArray }, function(data){
   // do something with received data!
});

Php will receive an array which will be name myphpvariable and it will contain the myJavascriptArray values.

Is it that ?