jquery Ajax调用访问WebService
[导读] 本文章来给各位朋友详细介绍关于jquery Ajax调用访问WebService的方法,有需要的朋友可参考对敌。jquery代码 代码如下复制代码 Jquery ajax({ type:post, datatype:json, success:fu
本文章来给各位朋友详细介绍关于jquery Ajax调用访问WebService的方法,有需要的朋友可参考对敌。
jquery代码
Jquery.ajax({
type:'post',
datatype:'json',
success:function(data){
//do something...
},
error:function(error){
//do something...
}
});
WebService处理
[WebMethod]
public string Hello(){
//return json
//方法1:手工拼接
return "{"Test":"Test-Value","测试":"测试-值"}";
//方法2:序列化json
//引入System.Runtime.Serialization.Json.DataContractJsonSerializer
//用WriteObject方法序列化成json
// 或者用Newtonsoft.Json.dll的JsonConvert.SerializeObject去处理
//方法3:把直接拼接的json串吐到浏览器,不需要return
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.ContentType = "application/json";
System.Web.HttpContext.Current.Response.Expires = 0;
System.Web.HttpContext.Current.Response.Cache.SetNoStore();
System.Web.HttpContext.Current.Response.Write(jsonContent);
System.Web.HttpContext.Current.Response.End();
}
查看评论 回复