Nithin Paul Nithin Paul - 3 months ago 26
Ajax Question

Invalid JSON primitive ERROR

Please Help. In my ajax call getting error Invalid JSON primitive, whats wrong with this following ajax call

$.ajax({
url: "/Precedent/ShowPartyContents", type: "POST",
contentType: 'application/json; charset=utf-8',
dataType: 'html',
data:{'partyId':party,'PartySelCombo':valueFrom,'DocumentId':DocId},
sucess:function(result){
alert("String"+ result);
//jq("#PartyTagContentArea-"+ pass cheyyenda id).html(data).fadeIn();
},
error : function( ts ){
alert("error :(" + ts.responseText);


}

});


Thanks

Answer

You are promising a content type of application/json but are sending a plain JS Object, which gets serialised as percentile-encoded-string by jQuery. This serialization might be far from valid JSON.

Change:

data: {'partyId':party,'PartySelCombo':valueFrom,'DocumentId':DocId},

to:

data: JSON.stringify({'partyId':party,'PartySelCombo':valueFrom,'DocumentId':DocId}),