Home > Web Front-end > JS Tutorial > body text

Jquery Ajax Learning Example 6 Makes a request to WebService and returns DataSet (XML) Asynchronous call_jquery

WBOY
Release: 2016-05-16 18:31:58
Original
1154 people have browsed it

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 the 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"] = "小花";
dr["Password"] = "aaaaaaaaa";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["Name"] = "Little Soldier";
dr["Password"] = "bbbbbbbbb" ;
dt.Rows.Add(dr);
ds.Tables.Add(dt);
return ds;
}

2. AjaxRequest.aspx
By clicking the button, 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) { //Executed on success Method
//Capture exceptions during processing and output
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) { //The callback function here will be executed when an error occurs
if (status == 'error') {
alert(status);
}
}
});
});
});
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template