Please Help. In my ajax call getting error Invalid JSON primitive, whats wrong with this following ajax call
$.ajax({
url: \"/Precedent/
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
You are facing the problem due to these lines:
contentType: 'application/json; charset=utf-8',
dataType: 'html',
first you are saying to application that the return result will be JSON type and in second line you say that the dataType will be HTML. Then how can it be return the json data.
To return and use the json data, you must specify the dataType:'json'
.
Use this:
contentType: 'application/json; charset=utf-8',
dataType: 'json',
Note: you have misspelled the success function so correct that also.