大佬教程收集整理的这篇文章主要介绍了jquery – 如何从2.0 asmx web服务返回JSON,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这里是电话:
$(document).ready(function() { $.ajax({ type: "POST",url: "Donationsservice.asmx/GetDate",data: "{}",contentType: "application/json; charset=utf-8",dataType: "json",success: function(msg) { // Hide the fake progress inDicator graphic. $('#RSSContent').removeClass('loading'); // Insert the returned HTML into the <div>. $('#RSSContent').html(msg.d); } }); });
这里是请求标头在fiddler中的样子:
POST /Donationsservice.asmx/GetDate http/1.1 x-requested-with: XMLhttprequest Accept-Language: en-us Referer: http://localhost:1238/text.htm Accept: application/json,text/javascript,*/* Content-Type: application/json; charset=utf-8 Accept-Encoding: gzip,deflate User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; eMusic DLM/4; .NET CLR 2.0.50727) Host: localhost:1238 Content-Length: 2 Connection: Keep-Alive Pragma: no-cache
我已经尝试将contentType设置为“text / json”并获得相同的结果。
这里是web服务方法:
<WebMethod()> _ Public Function GetDate() As String 'just playing around with Newtonsoft.Json Dim sb As new StringBuilder Dim sw As New IO.StringWriter(sb) Dim strOut As String = String.Empty Using jw As New JsontextWriter(sw) With jw .WriteStartObject() .WritePropertyName("datetiR_649_11845@e") .WriteValue(datetiR_649_11845@e.Now.ToString) .WriteEndObject() End With strOut = sw.ToString End Using Return strOut End Function
这里是它返回:
<?xml version="1.0" encoding="utf-8"?> <String xmlns="http://DMs.Webservices.org/">{"datetiR_649_11845@e":"11/13/2008 6:04:22 PM"}</String>
有人知道如何强制Web服务返回Json时,我问Json?
确保将[Scriptservice]装饰添加到您的Web服务。这就是指示ASP.NET AJAX框架的服务器端部分为正确形成的请求返回JSON。
此外,如果你在2.0中使用它,你需要在我的例子中删除“.d”。 The “.d” is a security feature that came with 3.5。
以上是大佬教程为你收集整理的jquery – 如何从2.0 asmx web服务返回JSON全部内容,希望文章能够帮你解决jquery – 如何从2.0 asmx web服务返回JSON所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。