Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I send an array to php through ajax?

Tags:

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?

like image 434
Lucia Avatar asked Nov 18 '08 18:11

Lucia


People also ask

Can we send array through 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.

Can AJAX be used with PHP?

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.


1 Answers

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 ?

like image 57
Dragouf Avatar answered Oct 18 '22 09:10

Dragouf