I have an ajax question for you all.
I want to return an array from an ajax call in php and then get the values from that array that I return for use with a jquery ajax call, but I don’t know how to do this. Can anyone point me in the right direction for a tutorial?
I know there’s a bunch of different encoding types for ajax responses (json and xml come to mind) but I don’t know really what there use is. Right now all I do is echo what I have as a response to get some things displayed on my page, but I want to change my current implementation to use an array as the response rather than just simple text. Though I don’t know where to start in looking at tutorials on how to do this.
Also, what is the point of using the encoding types if I can just echo my text out and get what I want? I guess I really don’t see the point of the json type or xml if I can just echo for display.
If you’re returning arrays, I think JSON is the best way to go.
Its actually really easy to do.
PHP:
Now use some jQuery:
The point of encoding your array is so that jQuery can pick it up as an array (with the help of JSON), and not just standard text.