0

I am creating a safari extension and in the backend I am using python to save the data. But I am unable to call the python function, it is giving me this error:

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

This is my python function url:http://localhost:8000/polls/add

I am using jquery/ajax to call the python function

This is my script code:

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); }
});
GGG
  • 620
  • 6
  • 27
dev
  • 49
  • 6

1 Answers1

0

It seems that you have a CORS issue. Try to disable it from Safari, check this out maybe it helps.

Vitalie Maldur
  • 505
  • 2
  • 18
  • Hi Vitalie Maldur, Yes, I have CORS issue, I checked your reply but it doesn`t help me. – dev Jun 21 '17 at 07:55
  • Did you try to set the `Access-Control-Allow-Origin: *` on the response from your server? not on your request. – Vitalie Maldur Jun 21 '17 at 08:05
  • Yes, I set like this, this is my def def helloworld(): resp = make_response() resp.headers['Access-Control-Allow-Origin'] = '*' return resp getting the same error – dev Jun 21 '17 at 13:16