jQuery Ajax POST call with JSON in Rest Web Service Issue

前端 未结 3 1622
生来不讨喜
生来不讨喜 2021-01-14 22:39

I want to post a JSON object from my page to a Rest WS. But when I am posting json through jQuery ajax call as output I am getting a HTML page with \"HTTP Status 405

3条回答
  •  迷失自我
    2021-01-14 23:00

    Try using type & contentType settings of ajax:

    type:'POST',
    contentType: 'application/json',
    

    Example:

    function loadDoc(){
      var num = '{"empid": 45,"name": "gaurav","salary":566.55}';
      $.ajax({
        url: 'http://localhost:9029/addS',
        method: 'POST',
        type:'POST',
        contentType: 'application/json',
        success: function(response){
          console.log("response::::"+response);
          $("#output").text(response);
        },
        error: function( jqXHR,textStatus, errorThrown){
          console.log("Error askdjk");
          console.log(jqXHR);
          console.log(textStatus);
          console.log(errorThrown);
        }
      });   
    }
    

提交回复
热议问题