【发布时间】:2017-11-23 21:13:21
【问题描述】:
我正在创建一个 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函数网址: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); }
});
【问题讨论】:
-
请编辑您的问题,而不是添加 cmets。
-
您好 GGG,感谢您的回复。好的,已编辑
标签: javascript python safari safari-extension