I have this statement in a js file in my app that loads in the beginning to check for session time outs every time after an ajax request.
if(window.jQuery)
{
$.ajaxSetup({
complete: function (xhr) {
if (xhr.getResponseHeader('SESS_TIMEDOUT') == "1") {
alert('Your session has timed out. Please login again!');
window.location = '/logout';
}
}
});
}
But then I started putting all my static files in a CDN and now I get this type of error in my console:
Uncaught TypeError: Cannot call method 'getResponseHeader' of undefine开发者_Python百科d
$.ajaxSetup.completeform.js:10
c.extend.handleCompletejquery-1.4.4.min.js:143
c.extend.ajax.A.onload.A.onreadystatechange
So apparently the xhr arg isn't getting passed in.
I also noticed that one of my scripts has a statement that uses the getScript() function with a URL that used to be '/js/script.js' but is now 'http://static.mydomain.com/js/script.js'. Could cross-domain issue be the culprit here?
Any ideas on how to solve this?
If you are requesting an ajax call to a different domain than your document resides on, then "yes", it would be an issue with cross-domain security. If you CDN is a completely different domain than your server domain where the ajax call goes, this can cause Same Origin issues if your main HTML page is put on the CDN.
This document describes the Same Origin Policy and there is a work-around for different sub-domains with a common root domain. That is one way to work-around the CDN issue, but it requires making the CDN be a sub-domain of your root domain, not a completely separate root domain.
When switching to a CDN, you will have to make sure any relative paths are still correct. getScript()
can load from any domain. It isn't restricted by same origin, but if you are using a relative path and you've changed the root path, you have to either make sure all things that use relative paths are also on the CDN or switch to absolute paths.
精彩评论