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
JSON can represent (sub)values of four primitive data types and of two compound data types. The primitive data types are string, number, boolean, and null. There is no way to declare the data type of a JSON value; rather, it emerges from the syntax of the representation.
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}),
Try with, remove " ' " from data,
data:{partyId:party,PartySelCombo:valueFrom,DocumentId:DocId}
Use single quote to assign your values like
Wrong:
$.ajax({ type: 'POST', contentType: 'application/json', dataType: 'json', url: 'WebService.asmx/Hello', data: { FirstName: "Dave", LastName: "Ward" } });
Right:
$.ajax({ type: 'POST', contentType: 'application/json', dataType: 'json', url: 'WebService.asmx/Hello', data: '{ FirstName: "Dave", LastName: "Ward" }' });
Please follow below link for clarifications
Invalid Json Premitive Possible Reason
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With