之间XMLHtt prequest,jQuery.ajax,jQuery.post,jQuery.get有什么区别 [英] What is the difference between XMLHttpRequest, jQuery.ajax, jQuery.post, jQuery.get

查看:124
本文介绍了之间XMLHtt prequest,jQuery.ajax,jQuery.post,jQuery.get有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将如何找出哪一种方法是最好的一个局面。任何人都可以提供一些例子来了解在功能和性能方面的差异。

how will i find which method is best for a situation. Can anybody provide some examples to know the difference in terms of functionality and performance.

推荐答案

  • XMLHtt prequest 在原浏览器对象的jQuery包装成一个更加实用和简化的形式和跨浏览器一致功能。

  • XMLHttpRequest in the raw browser object that jQuery wraps into a more usable and simplified form and cross browser consistent functionality.

    jQuery.ajax 是一个通用的Ajax请求的jQuery的,可以做任何类型和内容的要求。

    jQuery.ajax is a general Ajax requester in jQuery that can do any type and content requests.

    jQuery.get jQuery.post ,另一方面他只能发出GET和POST请求。如果你不知道这些是什么,你应该检查 HTTP协议学着点儿。在内部这两个功能使用 jQuery.ajax ,但他们使用您不必为自己设定从而简化GET或POST请求相比,使用特定的设置 jQuery.ajax 。 GET和POST是最常用的HTTP方法呢(比DELETE,PUT,HEAD甚至其他很少使用外来)。

    jQuery.get and jQuery.post on the other hand can only issue GET and POST requests. If you don't know what these are, you should check HTTP protocol and learn a little. Internally these two functions use jQuery.ajax but they use particular settings that you don't have to set yourself thus simplifying GET or POST request compared to using jQuery.ajax. GET and POST being the most used HTTP methods anyway (compared to DELETE, PUT, HEAD or even other seldom used exotics).

    所有的jQuery函数中使用 XMLHtt prequest 对象的背景,但提供您不必自己动手做额外的功能。

    All jQuery functions use XMLHttpRequest object in the background, but provide additional functionality that you don't have to do yourself.

    因此​​,如果你使用jQuery我强烈建议你使用jQuery功能的。忘掉 XMLHtt prequest 干脆。使用适当的jQuery请求函数的变化而在其他情况下用 $。阿贾克斯()。所以,不要忘记还有其他常见的jQuery的Ajax相关功能 $获得() $。员额() $。阿贾克斯()。那么你可以使用 $。阿贾克斯()为您的所有要求,但你必须写多一点code,因为它需要更多的选择调用它。

    So if you're using jQuery I strongly recommend that you use jQuery functionality only. Forget about XMLHttpRequest altogether. Use suitable jQuery request function variations and in all other cases use $.ajax(). So don't forget there are other common jQuery Ajax related functions to $.get(), $.post() and $.ajax(). Well you can just use $.ajax() for all of your request, but you will have to write a little more code, because it needs a bit more options to call it.

    这就像你将能够自己买一辆汽车引擎,你必须创建一个全车周围有转向,刹车等..汽车制造商生产完成车,具有友好的人机界面(踏板,方向盘等等),所以你不必自己做这一切。

    It's like you would be able to buy yourself a car engine that you'd have to create a whole car around it with steering, brakes etc... Car manufacturers produce completed cars, with a friendly interface (pedals, steering wheel etc.) so you don't have to do it all yourself.

    这篇关于之间XMLHtt prequest,jQuery.ajax,jQuery.post,jQuery.get有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆