ajax請求: $(function () { $.ajax({ url: "index.aspx?method=send", success: function (data) { JSON.parse(data).forEach(function (item) { console.log(item ...
ajax請求:
$(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返回數據:
if(Request["method"]!=null)1
{
//查詢資料庫的數據
string sql = "select * from EHS_Role";
DataTable dt = DBHelper.ExecuteDataTable(sql, System.Data.CommandType.Text);
string json = JsonConvert.SerializeObject(dt);
//向客戶端寫回數據2
Response.Clear();
Response.ContentType = "text/plain";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.Write(json);
Response.End();
}
備註:
1.因為載入頁面首先載入的是.cs,為了防止第一次運行程式就直接向頁面寫入結果
2.為了防止返回的結果亂碼