先在Web.config中的System.Web节点下添加如下代码,使其支持Get请求:
<webServices> <protocols> <add name="HttpGet"/> <add name="HttpPost"/> </protocols>
再在需要使用Get请求的方法头前加
1 [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json, XmlSerializeString = false)]
ScriptMethod的命名空间为:
using System.Web.Script.Services;
如果期望返回的是json格式的字符串,不加xml标记,在jQuery的ajax请求中加上contentType:"application/json;utf-8"