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:
- Maybe you will never want to use ActiveX controls and always use the native XMLHttpRequest-object.
- Maybe you want to change the url at the last time.
- 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).
- Maybe you do a fallback to use "ajax" through iframes if XMLHttpRequest is not available.
- Etcetera.
精彩评论