Skip to content
Advertisement

How to pass Array with values using Ajax in jquery and get the values in Php page

I have an ajax posted parameter as below:

JavaScript

Where value in the my_ary = Array([0]=> Test Text,[1]=> test Text2)

Now i need to get values from this array using a foreach() loop like this:

JavaScript

But it is showning the following error

An invalid arguments passed to foreach loop

Advertisement

Answer

Convert the array to a string before passing it like so:

JavaScript

Or if it’s a complex array consider JSON:

JavaScript

In case of your associative array

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement