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:
[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:
//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);
}
}
});
});
});
Statement: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