3

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

rachana
  • 3,344
  • 7
  • 30
  • 49

3 Answers3

3

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

Community
  • 1
  • 1
Karthik
  • 1,363
  • 2
  • 12
  • 13
  • Not working,`$.post()` not accept `type:'POST'` as a parameter – rachana Jun 22 '15 at 11:13
  • Then you can either change the datatype to 'json' instead of 'jsonp' or change the 'post' function to 'ajax' – Karthik Jun 22 '15 at 11:14
  • If I use `$.ajax()` method with `datatype:jsonp` and `type:'POST'` it also gives same error as above – rachana Jun 22 '15 at 11:20
  • This is a case of cross-domain json object fetching I guess. You can try adding a filter or something. Please check this answer- http://stackoverflow.com/a/26803206/354307 – Karthik Jun 22 '15 at 11:22
  • jQuery library [has type already] in post function (https://github.com/jquery/jquery/blob/2.2.4/src/ajax.js#L836), adding it by hand here is useless – vladkras Mar 10 '19 at 06:48
1

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

Sreelal P Mohan
  • 309
  • 1
  • 11
0

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

James Joyce
  • 1,694
  • 18
  • 20