2013-06-12 55 views
0

我的頁面已經工作了一段時間,突然它給了我這個跨域請求錯誤。奇怪的是我正在對文件進行相對請求,所以我不明白爲什麼我會得到這個。同一個域上的訪問控制 - 允許 - 來源錯誤

錯誤:

選項https://www.aliahealthcare.com/php/central.php?logout=true 產地https://aliahealthcare.com沒有被訪問控制允許來源允許的。

發送的jquery-1.7.2.min.js:4 f.extend.ajax的jquery-1.7.2.min.js:4 註銷aliahealthcare.com/:841 拾取器aliahealthcare.com/:901 (匿名功能)aliahealthcare.com/:713 f.event.dispatch的jquery-1.7.2.min.js:3 h.handle.i的jquery-1.7.2.min.js:3

的XMLHttpRequest不能加載https://www.aliahealthcare.com/php/central.php?logout=true

來源https://aliahealthcare.com不被訪問控制允許來源所允許。 aliahealthcare.com/:1

代碼:

function logout(){ 

     $.ajax({ 
      type: "GET", 
      url: "/php/central.php", 
        data: { logout: 'true' }, 
        success: function(msg) { 
        if(msg=='1'){ 

        location.reload(); 

        } 
        else if(msg=='0') { 
         alert("Logout Failed! Please try again!") 
        } 
        }, 
        error:function(msg){ 
        alert("Error"+msg); 
        } 

     }); 
    } 

結果輸出阿賈克斯的結果時:

Object {readyState: 1, setRequestHeader: function, getAllResponseHeaders: function, getResponseHeader: function, overrideMimeType: function…} abort: function (a){a=a||"abort",p&&p.abort(a),w(0,a);return this} always: function(){i.done.apply(i,arguments).fail.apply(i,arguments);return this} complete: function(){if(c){var a=c.length;n(arguments),j?l=c.length:e&&e!==!0&&(k=a,o(e[0],e[1]))}return this} done: function(){if(c){var a=c.length;n(arguments),j?l=c.length:e&&e!==!0&&(k=a,o(e[0],e[1]))}return this} error: function(){if(c){var a=c.length;n(arguments),j?l=c.length:e&&e!==!0&&(k=a,o(e[0],e[1]))}return this} fail: function(){if(c){var a=c.length;n(arguments),j?l=c.length:e&&e!==!0&&(k=a,o(e[0],e[1]))}return this} getAllResponseHeaders: function(){return s===2?n:null} getResponseHeader: function (a){var c;if(s===2){if(!o){o={};while(c=bG.exec(n))o[c[1].toLowerCase()]=c[2]}c=o[a.toLowerCase()]}return c===b?null:c} isRejected: function(){return!!i} isResolved: function(){return!!i} overrideMimeType: function (a){s||(d.mimeType=a);return this} pipe: function (a,b,c){return f.Deferred(function(d){f.each({done:[a,"resolve"],fail:[b,"reject"],progress:[c,"notify"]},function(a,b){var c=b[0],e=b[1],g;f.isFunction(c)?i[a](function(){g=c.apply(this,arguments),g&&f.isFunction(g.promise)?g.promise().then(d.resolve,d.reject,d.notify):d[e+"With"](this===i?d:this,[g])}):i[a](d[e])})}).promise()} progress: function(){if(c){var a=c.length;n(arguments),j?l=c.length:e&&e!==!0&&(k=a,o(e[0],e[1]))}return this} promise: function (a){if(a==null)a=h;else for(var b in h)a[b]=h[b];return a} readyState: 0 responseText: "" setRequestHeader: function (a,b){if(!s){var c=a.toLowerCase();a=m[c]=m[c]||a,l[a]=b}return this} state: function(){return e} status: 0 statusCode: function (a){if(a){var b;if(s<2)for(b in a)j[b]=[j[b],a[b]];else b=a[v.status],v.then(b,b)}return this} statusText: "error" success: function(){if(c){var a=c.length;n(arguments),j?l=c.length:e&&e!==!0&&(k=a,o(e[0],e[1]))}return this} then: function (a,b,c){i.done(a).fail(b).progress(c);return this} __proto__: Object

+2

「http:// blahblah.com」與「http:// www.blahblah.com」中的不同來快速解決問題跨域策略的條款。 – phpisuber01

+0

@ phpisuber01它應該沒關係,它仍然是一個相對路徑,暗示請求將使用原始域。 –

+0

@BradM同意,但他的選項/來源信息會有其他建議。 – phpisuber01

回答

0

的URL之間的區別是 「WWW」,我想這足以觸發「跨域」。你是對的,相對請求導致不同的URL是很奇怪的;也許這與JQuery的ajax方法有關。您可以通過手動輸入完整主機名或使用window.location

+0

我不想硬編碼名稱,以允許用戶使用具有相同代碼的www子域。 – Osman

+0

然後你可以去第二條路線。 window.location.host(或.hostname)會給你http://和下一個斜槓之間的所有內容。在這裏,它是「stackoverflow.com」。在Google上,它是「www.google.com」。我們經常將它用於我們的webapp,它通常運行在不同的服務器上。 – Katana314

相關問題