1. WebService. asmx:
Process business data and generate dataset (XML) data in the getdataset () method for jqueryrequest. aspx to call, Code As follows:
Copy code The 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;
}
2. 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 Code the 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 of execution upon successful execution
// capture exceptions during handling and output
try {
$ (result ). find ("Table1 "). each (function () {
$ ('# dd '). append ($ (this ). find ("name "). text () + "" + $ (this ). find ("password "). text ();
});
}< br> catch (e) {
alert (E);
return;
}< BR >},
error: function (result, status) {// when an error occurs, the callback function
If (status = 'error') {
alert (Status );
}< BR >});
});