rachana
rachana

Reputation: 3414

JQuery $.ajax(),$.post() sending GET as Request Method

I have gone through all the suggested links to find out the solution but still when I trying to make $.post() it sending GET as a Request_Method and it is giving me error

GET https://example.com/samewebservice/save 405 (Method Not Allowed)

It is a Cross Origin Request so I have enable all the CORS setting on server, If i execute $.get() method it is giving me response in JSON format successfully.

But when m trying to execute $.post() method it is giving me error.

POST ajax request

function postAjax(URL,jsonData){

  $.post(URL,jsonData,function(data){
    response = data;
     alert("In success");
     console.log(data);
  },"jsonp");
  return response;
}

On browser header I am getting this

enter image description here

Upvotes: 3

Views: 5961

Answers (3)

James Joyce
James Joyce

Reputation: 1764

I had a [FromBody] before my "HttpRequestMessage request" parameter; and this wasn't parsing correctly..........

Upvotes: 0

Sreelal P Mohan
Sreelal P Mohan

Reputation: 313

You can't POST using JSONP...it creates a <script> element to fetch data..which has to be a GET request.

Upvotes: 1

Karthik
Karthik

Reputation: 1411

Just a guess. Try adding the type also

function postAjax(URL,jsonData){
  $.post(URL,jsonData,
    type:'POST',
    function(data){
      response = data;
      alert("In success");
      console.log(data);
  },
  "jsonp");

  return response;
}

B/w the jsonp datatype might be the reason here. Check this answer

Upvotes: 3

Related Questions