Copy Code code as follows:
$.ajax ({
Async:true,//default True (asynchronous request)
Cache:true,//default True, set to False will not load request information from the browser cache.
Type: "POST",//default: Get request mode: [Post/get]
DataType: "xml",//default ["XML"/"HTML"] returns data type: ["XML"/"HTML"/"script"/"JSON"/"JSONP"]
URL: "Test.ashx",//default current address, send the requested address
Data: {key: ' value '},//sent to the server
Error:function (XML) {alert (' Error loading XML document ' + XML);}, called when//request failed
timeout:1000,//Set Request timeout
Success:function (XML) {//Request callback function parameter after success: Server returns data, data format.
$ ("#users"). empty ();
Using jquery to process XML data
$ (XML). Find (' Table '). each (function () {
var LoginName = $ (this). Find ("LoginName"). Text ();
var Name "). Text ();
$ ("#users"). Append ("<li>" + LoginName + "-" + name + "</li>");
});
/*
$ (XML). Find (' user '). each (function (i) {
var LoginName = $ (XML). Find ("User LoginName"). EQ (i). text ();
var user name "). EQ (i). text ();
$ ("#users"). Append ("<p>" + loginname + "</p>" + "<p>" + name + "</p><br/>");
})
$ (XML). Find ("Student"). each (function (i) {
var id "); Fetching objects
var id_value=$ (this). Children ("id"). text (); Fetching text
alert (id_value);//This is the value of the ID.
Alert ($ (this). attr ("email")); Here you can display the email attribute under student.
The final output, this is Cssrain, seemingly more jq than Macnie
$ (' <li></li> '). HTML (id_value). Appendto (' ol ');
});
*/
}
})
Returns XML data using the Ashx file:
Copy Code code as follows:
<%@ WebHandler language= "C #"%>
Using System;
Using System.Web;
Using System.Text;
Using System.Data;
public class Test:ihttphandler {
public void ProcessRequest (HttpContext context) {
Context. Response.statuscode = 200;
Context. Response.Cache.SetCacheability (Httpcacheability.nocache);
DataSet ds = new DataSet ("Accountlist");
ds = GetList ("account", "AccountId", "Loginname,name", 50,1,false, False, "1=1");
context. Response.ContentType = "Text/xml";
context. Response.Charset = "GB2312";
context. Response.Clear ();
context. Response.Write ("<?xml version=\" 1.0\ "encoding=\" Gbk\ ">\n" + ds. GETXML ());
/*
StringBuilder sb = new StringBuilder ();
Sb. Append ("<?xml version=\" 1.0\ "encoding=\" Gbk\ "?>");
Sb. Append ("<AccountList>");
Sb. Append ("<Account><loginname>Loro5</loginname><name>wulu</name></user>");
Sb. Append ("</Account>");
Context. Response.Write (sb.) ToString ());
*/
Context. Response.End ();
}
public bool IsReusable {
get {
return false;
}
}
}