1. WebService. asmx:
Process business data and generate DataSet (XML) data in the GetDataSet () method for JqueryRequest. aspx to call. The Code is as follows:
Copy codeThe Code is as follows:
[WebMethod]
Public DataSet GetDataSet ()
{
DataSet ds = new DataSet ();
DataTable dt = new DataTable ();
Dt. Columns. Add ("Name", Type. GetType ("System. String "));
Dt. Columns. Add ("Password", Type. GetType ("System. String "));
DataRow dr = dt. NewRow ();
Dr ["Name"] = "Xiaohua ";
Dr ["Password"] = "aaaaaaaaa ";
Dt. Rows. Add (dr );
Dr = dt. NewRow ();
Dr ["Name"] = "Xiao Bing ";
Dr ["Password"] = "bbbbbbbbbbb ";
Dt. Rows. Add (dr );
Ds. Tables. Add (dt );
Return ds;
}
Ii. AjaxRequest. aspx
Click the button to request the GetDataSet () method of WebService. asmx to obtain the XML data object. The Code is as follows:
Copy codeThe Code is as follows:
// Return DataSet (XML)
$ (Document). ready (function (){
$ ('# BtnDataset'). click (function (){
$. Ajax ({
Type: "POST ",
Url: "WebService. asmx/GetDataSet ",
Data :"{}",
DataType: 'xml', // The returned type is xml
Success: function (result) {// method executed when the call succeeds
// Capture and output exceptions during processing
Try {
$ (Result). find ("Table1"). each (function (){
$ ('# Dd '). append ($ (this ). find ("Name "). text () + "" + $ (this ). find ("Password "). text ());
});
}
Catch (e ){
Alert (e );
Return;
}
},
Error: function (result, status) {// when an error occurs, the callback function is executed.
If (status = 'error '){
Alert (status );
}
}
});
});
});