簡單的ajax執行個體

來源:互聯網
上載者:User

index.jsp

<%@ page contentType="text/html; charset=gbk"%><br /><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><br /> <html><br /> <head><br /> <title>Check.html</title></p><p> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><br /> <meta http-equiv="description" content="this is my page"></p><p> <!--<link rel="stylesheet" type="text/css" href="./styles.css" mce_href="styles.css">--></p><p> </head><br /> <mce:script type="text/javascript"><!--<br /> var http_request = false;<br /> function send_request(url) {//初始化、指定處理函數、發送請求的函數<br /> http_request = false;<br /> //開始初始化XMLHttpRequest對象<br /> if(window.XMLHttpRequest) { //Mozilla 瀏覽器<br /> http_request = new XMLHttpRequest();<br /> if (http_request.overrideMimeType) {//設定MiME類別<br /> http_request.overrideMimeType('text/xml');<br /> }<br /> }<br /> else if (window.ActiveXObject) { // IE瀏覽器<br /> try {<br /> http_request = new ActiveXObject("Msxml2.XMLHTTP");<br /> } catch (e) {<br /> try {<br /> http_request = new ActiveXObject("Microsoft.XMLHTTP");<br /> } catch (e) {}<br /> }<br /> }<br /> if (!http_request) { // 異常,建立對象執行個體失敗<br /> window.alert("不能建立XMLHttpRequest對象執行個體.");<br /> return false;<br /> }<br /> http_request.onreadystatechange = processRequest;<br /> // 確定發送請求的方式和URL以及是否同步執行下段代碼<br /> http_request.open("GET", url, true);<br /> http_request.send(null);<br /> }<br /> // 處理返回資訊的函數<br /> function processRequest() {<br /> if (http_request.readyState == 4) { // 判斷對象狀態<br /> if (http_request.status == 200) { // 資訊已經成功返回,開始處理資訊<br /> alert(http_request.responseText);<br /> } else { //頁面不正常<br /> alert("您所請求的頁面有異常。");<br /> }<br /> }<br /> }<br /> function userCheck() {<br /> var f = document.form1;<br /> var username = f.username.value;<br /> if(username=="") {<br /> window.alert("The user name can not be null!");<br /> f.username.focus();<br /> return false;<br /> }<br /> else {<br /> send_request('check1.jsp?username='+username);<br /> }<br /> }</p><p>// --></mce:script><br /> <body><br /> <form name="form1" action="" method="post"><br /> User Name:<input type="text" name="username" value=""> <br /> <input type="button" name="check" value="check" onClick="userCheck()"><br /> <input type="submit" name="submit" value="submit"><br /> </form><br /> </body><br /> </html><br />本文來自CSDN部落格,轉載請標明出處:http://blog.csdn.net/sunrisefe/archive/2006/01/16/580474.aspx 

 

check1.jsp

<%@ page contentType="text/html; charset=gb2312" language="java" errorPage="" %><br /> <%<br /> String username= request.getParameter("username");<br /> if("educhina".equals(username))<br /> {<br /> out.print("使用者名稱已經被註冊,請更換一個使用者名稱。");<br /> }<br /> else<br /> {<br /> out.print("使用者名稱尚未被使用,您可以繼續。");<br /> }<br /> %>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.