I am interested to know what minimal cross-browser Javascript code (jQuery is fine too) may be possible to check if the site that I want to send cross-domain AJAX requests supports CORS
.
I know jQuery has a way to check if the browser supports it. But I would really like to check if the remote site supports.
I thought I just needed to check the HTTP header, but of course, XHR will throw an exception when trying to do a cross-domain request for a site that doesn't support it.
But is there a way to verify that the exception thrown by XMLHttpRequest
was due to the site not supporting CORS
and not something else wrong? (It should not support XDomainRequest.)
In any case, I'm not sure if the best minimal / fast cross-browser way to get HTTP HEAD
using AJAX, which I assume is an easy way, not a page selection, etc.
Use case. Once I find out if the browser and the AJAX provider support CORS
or not, I can choose whether to send more efficient JSON
/ CORS
requests or return to JSONP
requests when necessary.
source share