請問該如何實現ajax異步請求,要訪問數據庫的那種 ?
3 回答
慕無忌1623718
TA貢獻1744條經驗 獲得超4個贊
1、Html代碼
| 123 | <input type="text" id="User"><input type="text" id="Psd"> <input type="button" onclick="Login();" id="登錄"> |
2、js代碼
| 123456789101112131415 | funcation Login(){$.ajax({ type: "post", contentType: "application/json", url: "../Backstage/AdminService.asmx/GetAdminList",//請求后臺方法 data: JSON.stringify({ Name: user,Password:psd}), success: function (result) { //判斷result.d的值; }, error: function (response) { var r = jQuery.parseJSON(response.responseText); alert("Message: " + r.Message); }}) } |
3、一般處理程序
| 123456 | [WebMethod] public bool GetAdminList(string Name;string Password) { //訪問數據庫 //成功返回true,失敗返回False; } |
暮色呼如
TA貢獻1853條經驗 獲得超9個贊
| 12345678 | 通過 AJAX 加載一段文本:jQuery 代碼:$(document).ready(function(){ $("#b01").click(function(){ htmlobj=$.ajax({url:"/jquery/test1.txt",async:false}); $("#myDiv").html(htmlobj.responseText); });}); |
另外,jquery還可以用$.post,$.get等方式,分別代表post請求和get請求的ajax
- 3 回答
- 0 關注
- 368 瀏覽
添加回答
舉報
0/150
提交
取消
