Ajax Response is enclosed in XML Prolog and String tag which causes Invalid JSON
Ajax Response is enclosed in XML Prolog and String tag which causes Invalid JSON
I am making an AJAX call to a ASP.NET WebMethod. The webmethod is returning a string in the following format:
{"data":[{"MemberNumber":"1","FirstName":"","LastName":"Patterson ","MiddleName":"","NationalityDesc":"","NationalityRefNbr":0,"Gender":null,"BirthDate":null,"MaritialStatus":null,"MaritialStatusRefNbr":0,"IdentityType":null,"IdentityRefNbr":0,"ParticipantType":null},{"MemberNumber":"","FirstName":"","LastName":"Patterson ","MiddleName":"","NationalityDesc":"","NationalityRefNbr":0,"Gender":null,"BirthDate":null,"MaritialStatus":null,"MaritialStatusRefNbr":0,"IdentityType":null,"IdentityRefNbr":0,"ParticipantType":null}]}
However when I check the XHR Response the JSON text array is enclosed in XML Prolog and a String tag:
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">{"data":[[{"MemberNumber":"" etc.....
</string>
I believe the Prolog and string tag is causing the Invalid JSON. Does anyone know how to prevent .NET from adding the prolog?
This question has an accepted answers - jump to answer
Answers
FYI the following link helped me solve this issue:
http://datatables.net/forums/discussion/20876/server-side-processing-setting-datatype-to-json#Comment_60508
After setting the contentType to application/json the JSON string returned to the browser was no longer enclosed in XML prolog or string tag.
Good to hear you got it working :-)
Allan