What is the difference between XMLHttpRequest, jQuery.ajax, jQuery.post, jQuery.get

后端 未结 6 1857
无人及你
无人及你 2020-11-29 16:11

How can I find out which method is best for a situation? Can anybody provide some examples to know the difference in terms of functionality and performance?

6条回答
  •  感动是毒
    2020-11-29 16:40

    jQuery.get is a wrapper for jQuery.ajax, which is a wrapper to XMLHttpRequest.

    XMLHttpRequest and Fetch API (experimental at this time) are the only in DOM, so should be the fastest.

    I saw a lot of information that is not accurate anymore, so I made a test page where anyone can test version from version which one is best at any time:

    https://jsperf.com/xhr-vs-jquery-ajax-vs-get-vs-fetch

    From my tests today shows that only jQuery isn't a clean or even a fast solution, the results for me in mobile or desktop shows that jQuery are, at least, 80% slower than XHR2, if you're using too much ajax, in mobile it will be take a lot of time to load a simple site.

    The usage itself is in the link too.

提交回复
热议问题