You will need to return JSON (or another data format supported by jQuery ajax ()) from your favorite.php file.
edit : it doesn't have to be json, but for multiple return values ββthis is easiest to parse. For example, if you returned xml or html, you would need to cross the nodes to return the value.
For example, if you returned:
{"user": "Joe", "success" : "pass", "message" : "favorite added" }
you should use:
function(response){ var user = response.user; var success = response.success;
The important thing to remember is to specify the data type in your ajax call as json. jQuery also supports other data types: xml, html, script, jsonp, text
I believe that html is used by default. And by writing php to return xml with correctly formatted headers in a php script, I can tell you what you sometimes have to specify the data type for jQuery to parse it correctly.
source share