开发者

What is the purpose of overriding the "xhr" property in $.ajaxSetup?

I could not find any answers about this via Google, so thought I can ask here:

For the jQuery $.ajaxSetup function, what is the purpose of overriding the xhr property? I see that in the documentation, it says:

Callback for creating the XMLHttpRequest object. Defaults to the ActiveXObject when available (IE), the XMLHttpRequest otherwise. Override to provide your own implementation for XMLHttpRequest or enhance开发者_JAVA技巧ments to the factory.

Why would someone want to manually do override the xhr object? Any examples?


Some examples I can think of:

  1. Maybe you will never want to use ActiveX controls and always use the native XMLHttpRequest-object.
  2. Maybe you want to change the url at the last time.
  3. Maybe you want to do some security checks before doing the Ajax request (not that this stops malicious users, only protects normal users against themselves).
  4. Maybe you do a fallback to use "ajax" through iframes if XMLHttpRequest is not available.
  5. Etcetera.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜