我正在创建一个safari扩展,在后端我使用python来保存数据。但是我无法调用python函数,它给了我这个错误:
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
这是我的python函数url:http://localhost:8000/polls/add
我使用jquery / ajax来调用python函数
这是我的脚本代码:
var action_url ="localhost:8000/polls/add";
params = 'contact_name=abc&contact_email=abc@gmail.com&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); }
});