如何實現(xiàn)ajax異步請求,要訪問數(shù)據(jù)庫的那種
3 回答

幕布斯6054654
TA貢獻1876條經(jīng)驗 獲得超7個贊
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) { //訪問數(shù)據(jù)庫 //成功返回true,失敗返回False; } |

慕田峪7331174
TA貢獻1828條經(jīng)驗 獲得超13個贊
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
添加回答
舉報
0/150
提交
取消