請輸入程式碼 ajax.asp <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=big5"/> <title>Ajax check</title> <script src="jquery.js" type="text/javascript"></script> <script language="JavaScript"> checkRegAcc = function (){ if ($('#text1').val().length >=4) { $.ajax( { url: 'check.asp', type: 'GET', data: { id: $('#text1').val() }, error: function(xhr) { alert('Ajax request 發生錯誤'); }, success: function(response) { $('#msg').html(response); $('#msg').fadeIn(); } } ); }else{ $('#msg').html(''); } }; </script> </head> <body> <form> <input name="text1" id="text1" type="text" onblur="checkRegAcc()" /> <span id="msg"></span> </form> </body> </html> check.asp <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=big5" /> <title>check</title> </head> <body> <% set Conn = Server.CreateObject("ADODB.Connection") Conn.ConnectionString = "driver={SQL Server};UID=user;Database=user;Server=.;PWD=sa;" Conn.Open() id=replace(trim(request("id")),"'","") set rs=server.CreateObject("adodb.recordset") rs.Open "Select * from table Where id='" & request("id") & "'" ,conn,1,1 if not( rs.bof and rs.eof) then ret = "<span style='color:green'>此工號可以使用</span>" else ret = "<span style='color:red'>此工號已經有人使用</span>" end if RS.Close() Conn.Close() response.write(ret) %> </body> </html>
2012年10月5日 星期五
asp ajax 範例三
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言