Repository navigation
Simplify XHR detection #1967
Description
Activity
Sounds like a great idea; I only see references to it in test/unit/support.js and those can go away as well since we don't guarantee any
jQuery.supportproperties. Would you like to file a PR?XMLHttpRequest object is supported in all modern browsers
Right, but you can disable it in IE, but i'd say we shouldn't support that anymore.
try..catchwas always weird me out here, it's understanble why it was used for activeX but I hear it's pointless.xhrmethod was never documented and tested so i'd say we should get rid of it too.Not sure about
support.corsproperty, we never used it anywhere else, but it might be useful for tests, so i either remove it or add tests for it./cc @jaubourg
Not sure about
support.corsproperty, we never used it anywhere else, but it might be useful for tests, so i either remove it or add tests for it.withCredentialsproperty has appeared only in IE10 (MSDN) so you cannot just drop that check.- added 2 commits that reference this issue
on Dec 26, 2014 XMLHttpRequest object is supported in all modern browsers
Right, but you can disable it in IE, but i'd say we shouldn't support that anymore.
I tend to agree, especially on
master(I'd like to hear @dmethvin's thoughts on that, though).Not sure about
support.corsproperty, we never used it anywhere else, but it might be useful for tests, so i either remove it or add tests for it.IMO we should keep it. Our detection code is not perfect in weird setups so it's nice if people can workaround potential problems just by setting
jQuery.support.corstotrue(even if we don't officially support it). See e.g. #1881.XMLHttpRequest object is supported in all modern browsers
Right, but you can disable it in IE, but i'd say we shouldn't support that anymore.
I tend to agree, especially on
master(I'd like to hear @dmethvin's thoughts on that, though).Hence the
try/catchstatement that prevents crashing at startup.Not sure about
support.corsproperty, we never used it anywhere else, but it might be useful for tests, so i either remove it or add tests for it.IMO we should keep it. Our detection code is not perfect in weird setups so it's nice if people can workaround potential problems just by setting
jQuery.support.corstotrue(even if we don't officially support it). See e.g. #1881.We should definitely keep
support.cors, meaning we need to create an xhr at startup, meaning we need thetry/catch.We should definitely keep
support.cors, meaning we need to create an xhr at startup, meaning we need thetry/catch.Does IE with native XHR disabled still have the
XMLHttpRequestglobal but it just crashes? Otherwise it'd be better to change the code so that it's a noop or sth like that and not rely ontry/catch.(on a side note, we also need to think about those non-browser environments that may not have an xhr implementation into which we may not want to fail miserably)
Does IE with native XHR disabled still have the
XMLHttpRequestglobal but it just crashes? Otherwise it'd be better to change the code so that it's a noop or sth like that and not rely ontry/catch.Whether it's
undefinedor throws an exception when the constructor is invoked is irrelevant since both cases are handled by thetry/catch. It's pretty solid as is which was the point.(on a side note, we also need to think about those non-browser environments that may not have an xhr implementation into which we may not want to fail miserably)
Right; I'll land #1949 in a moment so that we get covered here.
Whether it's
undefinedor throws an exception when the constructor is invoked is irrelevant since both cases are handled by thetry/catch.Right but if it never throwed then it'd be better to avoid
try/catch. But I guess we don't have the guarantee.But I guess we don't have the guarantee.
Exactly. The module we're talking about being ajax, I tend to apply a "better safe than sorry" policy ;)
Does IE with native XHR disabled still have the XMLHttpRequest global but it just crashes?
I've checked IE11 — you just cannot disable
XHRat all. Will check IE9 and IE10 later.Checked IE9: even when you disable
XHR,window.XMLHttpRequestis still available.IMO we should keep it. Our detection code is not perfect in weird setups so it's nice if people can workaround potential problems just by setting jQuery.support.cors to true (even if we don't officially support it).
Then we should document and support it, otherwise we will face more problems in the future. But i wouldn't do that, the only reason i see to leave it in, is for the tests.
Besides, there are way to do that, documented way. Whereas setting
jQuery.support.corsis like usingajaxSetupwhich is not a preferable way, if we say that it's okay, then we're inviting user to change other support properties if he feels like it :-(.@jaubourg it would be interesting to see in what unsupported envs we would fail, if we would, it would be on the low amount of users, but if we wound't, then we could avoid the "just in case" code.
8 remaining items
- added a commit that references this issue
on Aug 21, 2019 - added a commit that references this issue
on Aug 22, 2019 - added a commit that references this issue
on Aug 26, 2019 - locked as resolved and limited conversation to collaborators
on Feb 22, 2020
This is the
XMLHttpRequestobject detection code:https://github.com/jquery/jquery/blob/master/src/ajax/xhr.js
support.ajaxis used nowhere in the code and is not documented,XMLHttpRequestobject is supported in all modern browsers (including Android 2.3, iOS 6.1, Opera 12 and IE 9 — caniuse.com).Why not remove
xhrSupportedvariable together withsupport.ajaxandtry-catchblock?