Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

POST gets converted to GET, when sending request via local apache

I am trying to send a post request with the following code. But the request goes as GET request, instead of POST. How to fix this.

$.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 am getting XMLHttpRequest cannot load https://example.com. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. The response had HTTP status code 401.

When removed the header Access-Control-Allow-Origin, I am getting a 404 error

like image 251
gates Avatar asked Oct 30 '22 13:10

gates


1 Answers

I don't think, you can use a POST method with jsonp request. jsonp callbacks only for with GET method. Have a look at link .

like image 105
Sudipta Mondal Avatar answered Nov 09 '22 23:11

Sudipta Mondal