POST is converted to GET when sending a request through local apache

I am trying to send a mail request with the following code. But the request is sent as a GET request, not a POST request. How to fix it.

$.ajax({ url: 'https://www.exampleurl.com', method: 'POST', headers: {"Access-Control-Allow-Origin": true}, data: {url:'bla',call:"trans"} dataType: 'jsonp', success: function(data){ console.log('succes: '+data); } }); 

This is the error I get XMLHttpRequest cannot load https://example.com . The response to the request before the flight does not pass the access control check. There is no "Access-Control-Allow-Origin" header on the requested resource. Origin ' http: // localhost ' is therefore not allowed. The response was an HTTP 401 status code.

When I delete the Access-Control-Allow-Origin header, I get 404 error

+5
source share
2 answers

I don’t think you can use the POST method with jsonp request. jsonp callbacks for the get method only. Check out the link .

+2
source

You do not need to pass parameters in the url attribute if you want to send a POST request, use the data attribute instead, see jQuery.ajax () :

 $.ajax({ url: 'https://www.exampleurl.com', method: 'POST', data: {q:1, q2:2}, headers: {"Access-Control-Allow-Origin": true}, dataType: 'jsonp', success: function(data){ console.log('succes: '+data); } }); 

Hope this helps.

0
source

Source: https://habr.com/ru/post/1237975/


All Articles