【问题标题】:How to call python function from safari extension如何从 safari 扩展中调用 python 函数
【发布时间】: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-Ori‌​gin', '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


【解决方案1】:

您似乎遇到了CORS 问题。尝试从 Safari 中禁用它,check this out 可能会有所帮助。

【讨论】:

  • 嗨,Vitalie Maldur,是的,我遇到了 CORS 问题,我查看了您的回复,但对我没有帮助。
  • 您是否尝试在服务器的响应中设置Access-Control-Allow-Origin: *?不是您的要求。
  • 是的,我是这样设置的,这是我的 def def helloworld(): resp = make_response() resp.headers['Access-Control-Allow-Origin'] = '*' return resp getting同样的错误
猜你喜欢
  • 2018-05-25
  • 2011-01-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多