开发者

jquery with datatype json doesn't work, but parseJSON of text works

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜