With AJAX, when we perform a JSON request, we first have to pass the response received through eval
:
var quote=eval("(" + xhr.responseText + ")");
Afterwards, to use some information from it, one has to do some old-school JavaScript:
document.getElementById("textarea").value=xhr.responseText;
...or to use a specific piece of information we use createTextNode
like this:
// price is retrieved from PHP.
var text=document.createTextNode(price + ":" + quote.price);
Coming to jQuery, the same thing is as simple as this:
$.get("file.php",function(data){
var text=data.price;
});
Why do I need to use AJAX at all when there are AJAX methods available in jQuery itself?
I have no idea about the advanced things as to what AJAX can and jQuery can't or vice-versa. What are AJAX and jQuery each good for and when should I use which?