我正在創建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-Origin', 'localhost');
},
xhrFields: { withCredentials: true },
crossDomain: true,
data: JSON.stringify(params),
error: function (e) { alert('error = '+e) },
success: function (data) { alert(data); }
});
請編輯您的問題,而不是添加評論。 – GGG
嗨GGG, 感謝您的回覆。 好的,編輯 – dev