First, Webservice.asmx:
Processing business data, generating DataSet (XML) data in the GetDataSet () method for jqueryrequest.aspx calls, as follows:
Copy Code code 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" = "Floret";
dr["Password"] = "aaaaaaaaa";
Dt. Rows.Add (DR);
Dr = dt. NewRow ();
dr["Name" = "Soldier";
dr["Password"] = "bbbbbbbbb";
Dt. Rows.Add (DR);
Ds. Tables.add (DT);
return DS;
}
Second, ajaxrequest.aspx
Get the XML data object by clicking on the button to request the Webservice.asmx GetDataSet () method. The code is as follows:
Copy Code code as follows:
return DataSet (XML)
$ (document). Ready (function () {
$ (' #btnDataset '). Click (function () {
$.ajax ({
Type: "POST",
URL: "Webservice.asmx/getdataset",
Data: "{}",
DataType: ' xml ',//returned type is XML
Success:function (Result) {//method of execution when successful
captures exceptions during processing and outputs
try {
$ (Result). Find ("Table1"). each (function () {
$ (' #dd '). Append ($ (this). Find ("Name"). Text () + "" + $ (a). Find ("Password"). Text ());
});
}
catch (e) {
Alert (e);
Return
}
},
Error:function (result, status) {//The callback function is executed here when an error occurs
if (Status = = ' Error ') {
alert (status);
}
}
});
});
});