jquery Code
The code is as follows |
Copy Code |
Jquery.ajax ({
Type: ' Post ',
DataType: ' JSON ',
Success:function (data) {
Do something ...
},
Error:function (Error) {
Do something ...
}
});
|
WebService processing
[WebMethod]
The code is as follows |
Copy Code |
public string Hello () {
Return JSON
Method 1: Hand stitching
Return "{" Test ":" Test-value "," Testing ":" Test-value "}";
Method 2: Serialization of JSON
Introduction of System.Runtime.Serialization.Json.DataContractJsonSerializer
Serializing into JSON using the WriteObject method
Or use Newtonsoft.Json.dll's jsonconvert.serializeobject to deal with it.
Method 3: Spit directly into the JSON string to the browser, do not need to 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 ();
} |
This is achieved, but some friends say that the return of the XML data, later found the URL problem,
code is as follows |
copy code |
Page_Load ( Object sender, EventArgs e) { String method = Request.qu Erystring["Method"]; if ("Hello"). Equals (method)) { //Copy the WebService method or directly call WebService } } |