Posting JSON using JQuery and to set HTTP content type - 'application /json' Posting JSON using JQuery and to set HTTP content type - 'application /json' ajax ajax

Posting JSON using JQuery and to set HTTP content type - 'application /json'


Can you try this,

$.ajax({    beforeSend: function(xhrObj){        xhrObj.setRequestHeader("Content-Type","application/json");        xhrObj.setRequestHeader("Accept","application/json");    },    type: "POST",    url: uri,           data: jsonStrJson,                   dataType: "json",    success: function(json){       console.log(json);    }});


"contentType" instead "contentTYpe" should also solve the problem. ;)


Also for setting http request header parameters you can try this approach:

$.ajax({       type        :   'POST'  ,       url         :   uri,       data        :   jsonStrJson,       headers     : { 'Content-Type': 'application/json' }, //this line       success     :   successFunction        });