Ajax Call, Difference between Java Script Ajax call and JQuery Ajax call

Is there any difference if the ajax call is made through a pure Java script path, jQuery path or JASON path.

I developed several codes using a Java script and thought if I should change it to jQuery if there are any additional benefits.

If there is no difference, I would prefer to leave it that way and think about it in my next implementation.

+4
source share
2 answers

jQuery is a JavaScript library - it offers a set of functions as helpers, they can include fragments of common functions, but also hacks for different qwerks browsers.

When creating an AJAX call, several factors must be considered, some of which must be different for different browsers. Using jQuery, they do the job for you, and you can just use one convenient function instead of writing your own patch and having all the testing yourself.

+1
source

There is no jQuery way or JavaScript. jQuery is JavaScript. JavaScript is a language, and jQuery is a library of functions written and used with JavaScript. I'm not sure what you mean by JASON (I think you mean JSON) if you don't mean JSONP.

Ajax calls are usually made with an XMLHttpRequest object - at least for now. IE6 and other older browsers may support ajax using other methods such as ActiveX, and even older browsers may not support it at all.

$.ajax , the central jQuery ajax method does a lot of work, and you can see what it is , but you cannot understand it. Important line:

 jQuery.ajaxSettings.xhr = function() { try { return new XMLHttpRequest(); } catch( e ) {} }; 

Later we see xhr = options.xhr() , and then xhr.send . This is the code you would use to create an ajax request using JavaScript without using jQuery.

$.ajax also does many other things, since it can handle JSONP (which does not use XMLHttpRequest) transparently, as well as a ton of other things, such as supporting various options, setting headers using different methods, etc. $.ajax or the jQuery method is just a wrapper for what you think is a JavaScript method.

+1
source

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


All Articles