JQuery vs AJAX

With AJAX, when we execute a JSON request, we first need to pass the response received through eval :

 var quote=eval("(" + xhr.responseText + ")"); 

Then, in order to use some information from it, you need to make some JavaScript of the old version:

 document.getElementById("textarea").value=xhr.responseText; 

... or use a specific piece of information that we use createTextNode as follows:

 // price is retrieved from PHP. var text=document.createTextNode(price + ":" + quote.price); 

Getting started with jQuery, the same is simple:

 $.get("file.php",function(data){ var text=data.price; }); 

Why do I even need to use AJAX when there are AJAX methods in jQuery?

I have no idea about the advanced things that AJAX can and jQuery cannot, or vice versa. What is AJAX and jQuery for each product, and when should I use it?

+4
source share
3 answers

jQuery is a javascript library that simplifies javascript writing in terms of cross browser errors and provides several utility methods. Ajax is one of the methods in javascript, with which you get access to the code on the server side and manipulate your dom with the results that you get from it. jQuery provides cross-browser issues, free wrapper methods in the case of AJAX also to do the same. So jQuery is just a help library that makes it easier for you to work with a few things, one of which may be ajax.

+3
source

Remember that jquery is an ajax frame library. Ajax is an asynchronous communication mechanism that can be implemented using XMLHttpRequest (xhr) or jquery. jQuery is a third party supported library. One of these mechanisms is enough to implement Ajax functionality.

0
source

The jQuery ajax method is great and powerful, it can handle everything as needed.

There are various methods in jquery to make AJAX calls according to your requirements, but they are all synonymous with the ajax jquery method.

for json you can use $.getJSON(url,[data],function(response){});

to place data that you can use `$ .post (URL, [Data], function (response) {});

to receive the request, you can use `$ .get (URL, [Data], function () {});

and if you want to use the ajax method for all these things, you need to pass different arguments as per your requirement

 $.ajax({ 'url':you url, 'type':request type, 'data':your data, 'success':success handler function, 'error':error handler function, /*and many more*/ )} 

read jquery documentation for full details

0
source

Source: https://habr.com/ru/post/1388563/


All Articles