相关疑难解决方法(0)

如果ContentType不是JSON,我可以从.asmx Web服务返回JSON吗?

我想使用ajax和jquery将表单发布到.asmx webservice,并将Webservice中的值作为JSON返回.

我正在使用ASP.NET 4.0.我知道为了从Web服务返回JSON,需要设置以下内容:(1)dataType:"json"(2)contentType:"application/json; charset = utf-8",(3)type:"POST" (4)将数据设置为某物.我测试了这个并且它工作正常(即我的webservice将数据作为JSON返回)如果所有**四都设置**.

但是,让我说在我的情况下我想做一个标准的表单帖子,即test1 = value1&test2 = value2所以contentType不是JSON但我想要回JSON {test1:value1}.这似乎不起作用,因为contentType是" application/x-www-form-urlencoded "而不是" application/json; charset = utf-8 ".

谁能告诉我为什么我不能这样做?我必须明确发送JSON以获取JSON,但如果你不使用JSON(即发布urlencoded contenttype),那么webservice将返回XML.

非常感谢任何见解:)

jquery json web-services response.contenttype

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

jquery ×1

json ×1

response.contenttype ×1

web-services ×1