Jquery Ajax Learning Instance 6 sends a request to WebService, returning a dataset (XML) Asynchronous Call _jquery

Source: Internet
Author: User
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);
}
}
});
});
});
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.