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?
You can simply pass a JavaScript Array variable in the $. ajax as any other variable. On PHP script you can directly use it as a normal PHP Array.
Start Using AJAX Today In our PHP tutorial, we will demonstrate how AJAX can update parts of a web page, without reloading the whole page. The server script will be written in PHP. If you want to learn more about AJAX, visit our AJAX tutorial.
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 ?
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