Hasnain Hayder Hasnain Hayder - 8 months ago 34
Ajax Question

How to get page specific content using JQUERY AJAX

i want to fetch an associative array from remote page. I will send request using GET Method and in repsonse after some calculation page will return an associative array.
Something like this

Array ( [likes] => 4 [dislikes] => 5 [like_width] => 44 [dislike_width] => 55 [message] => [dislike_button] => [like_button] => )

Now i want to fetch these values and want to use on my page.
Thanks you in advance


You need to return data in JSON format, otherwise Javascript will not be able to parse the output.

Use json_encode($yourArray) to convert an array to a string in JSON format.

If you add the header to return the type "application/json" JavaScript just read an js object. If the return type is "text/html" (the default) you need to convert the sctring to JSON using JSON.stringify(data).