Ajax requests:
$ (function () {
$.ajax ({
URL: "Index.aspx?method=send",
Success:function (data) {
Json.parse (data). ForEach (function (item) {
Console.log (item);
})
},
Error:function (xhr,status) {
Console.log (status);
}
})
})
Aspx.cs Return Data:
if (request["method"]!=null)1
{
//Querying the database for data
String sql = "SELECT * from Ehs_role";
DataTable dt = dbhelper.executedatatable (sql, System.Data.CommandType.Text);
string json = jsonconvert.serializeobject (DT);
//write back data to client 2
response.clear ();
Response.ContentType = "Text/plain";
response.contentencoding = System.Text.Encoding.UTF8;
Response.Write (JSON);
Response.End ();
}
Note:
1. Because the loading page first loads the. cs, in order to prevent the first run of the program directly to the page to write results
2. In order to prevent the return of the result garbled
Ajax request and ASPX return data