I have an asp.ne开发者_Python百科t asmx webmethod that returns the following response:
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">{"field1":"1","field2":"2","field3":"3","field4":"4"}</string>
I am calling this webmethod using the jquery ajax function. If I specify dataType: 'json', I get a parse error. However, if I omit this statement, it returns successfully and if in the success function I execute jQuery.parseJSON(res.text), it correctly works.
What am I doing wrong? Is my webservice returning bad header information which is causing the ajax call with dataType: 'json' to fail?
Your webservice is returning XML, not JSON.
datatype: 'json'
requires that the server return pure JSON, not JSON wrapped in an XML tag.
I have always just return the
{"field1":"1","field2":"2","field3":"3","field4":"4"}
with no xml wrapper and never had a problem.
精彩评论