簡體   English   中英

XMLHttpRequest無法加載數據。 請求的資源上不存在“ Access-Control-Allow-Origin”標頭

[英]XMLHttpRequest cannot load data. No 'Access-Control-Allow-Origin' header is present on the requested resource

我正在嘗試創建我的第一個API並將JQuery與Ajax結合使用以提交登錄表單。 問題是在控制台中,我收到響應“ XMLHttpRequest無法加載數據。所請求的資源上沒有'Access-Control-Allow-Origin'標頭。”

我已使用GET請求連接到我的API,並在其中定義了標頭Access-Control-Allow-Origin,但是我不知道為什么我的Ajax請求失敗。

這是google chrome開發人員窗口的屏幕截圖:

開發者截圖

這是請求數據的JQuery代碼(已刪除提交觸發器和其他不相關的部分)

$.ajax({
    type: "POST",
    url: "http://api.subjectplanner.co.uk",
    data:{json:"true",com:"login",username:$('#LoginUsername').val(),password:$('#LoginPassword').val()},
    success: function(Response) {
        var Data = $.parseJSON(Response);
        if(Data.loginerror==0){
            $.cookie("SID", Data.sid, {expires:Data.expire, path:'/', domain:'.subjectplanner.co.uk'});
            alert("You have been logged in!");
        }else{
            $('#LoginFormError').html(Data.loginmessage);
            $('#LoginFormError').slideDown();
        }   
    }
});

拼寫檢查,請始終進行拼寫檢查!

我拼錯了原產地(如果您看截圖,我已經輸入了orgin)。 我已經解決了這個問題!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM