2017-06-21 45 views
0

我正在創建safari擴展,並在後端使用python保存數據。但我無法調用Python函數,它給我這個錯誤:如何從Safari瀏覽器擴展中調用python函數

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. 

這是我的Python功能網址:http://localhost:8000/polls/add

我使用jQuery/AJAX調用Python函數

這是我的腳本代碼:

var action_url ="localhost:8000/polls/add"; 
params = 'contact_name=abc&[email protected]&content=here is content'; 
$.ajax({ 
    url: action_url, 
    type: 'GET', 
    beforeSend: function(xhr){ 
     xhr.setRequestHeader('Access-Control-Allow-Ori‌​gin', 'localhost'); 
    }, 
    xhrFields: { withCredentials: true }, 
    crossDomain: true, 
    data: JSON.stringify(params), 
    error: function (e) { alert('error = '+e) }, 
    success: function (data) { alert(data); } 
}); 
+0

請編輯您的問題,而不是添加評論。 – GGG

+0

嗨GGG, 感謝您的回覆。 好的,編輯 – dev

回答

0

看來你有CORS問題。嘗試從Safari中禁用它,check this out也許它有幫助。

+0

嗨維塔利馬爾杜爾, 是的,我有CORS的問題,我檢查了你的答覆,但它並沒有幫助我。 – dev

+0

您是否嘗試在服務器響應中設置「Access-Control-Allow-Origin:*」?不是根據你的要求。 –

+0

是的,我設置這樣的,這是我的高清 高清的HelloWorld(): RESP = make_response() resp.headers [ '訪問控制允許來源'] = '*' 回報RESP 越來越同樣的錯誤 – dev

相關問題