2017-06-21 47 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

相关问题