Am wondering if there is any method to check if the call is a cros开发者_Python百科s-domain call. Maybe something like a flag which tests if it is cross-domain so then I can use another approach.
For example:
$.ajax({
type: "POST",
url: "cross-domaincallURL",
success: function(response, status, xhr){
if OPTIONS then cross-domain
if not then not cross-domain
}
});
I suppose the easiest way would be to compare the "cross-domaincallURL" to the domain-part of window.location.
You could encapsulate that logic into a separate function or some how add it on to the ajax object (but that's another storey).
EDIT:
You can get the domain part of the current location via window.location.hostname https://developer.mozilla.org/en/DOM/window.location
I think you can get the AJAX requests URL in the beforeSend(jqXHR, settings) event. As it's passed the settings.
精彩评论