使用jQuery發送非同步請求

來源:互聯網
上載者:User

標籤:

具體格式如下

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%    String path = request.getContextPath();    String basePath = request.getScheme() + "://"            + request.getServerName() + ":" + request.getServerPort()            + path + "/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>    <head>        <meta charset="utf-8">        <title></title>        <script type="text/javascript" src="${pageContext.request.contextPath}/jquery-1.5.1.js">        </script>        <script type="text/javascript">            $(function() {                $("[name=name]").blur(function() {                    var name = $("[name=name]");                    $.ajax({                        //1.要請求的伺服器url                        url: "myfirstweb/LoginServlet",                        //2.data對象包含兩個請求參數,這兩個參數伺服器端可以使用request.getParameter()來擷取                        data: {method: "ajax",val: name},                        //3.表示是否為非同步請求(同步請求會等待伺服器返回的結果)                        async: true,                        //4.是否緩衝結果                        cache:false,                        //5.請求方式                        type: "POST",                        //6.伺服器返回的資料類型(json是js中的一個對象)                        dataType: "json", //或者為"xml"                        //7.這個函數會在伺服器執行成功時被調用,參數result是伺服器返回的值                        success: function(result) {                            $("label").text(result ? "使用者名稱可以使用" : "使用者名稱已存在!")                        },                    });                });            });        </script>    </head>    <body>        使用者名稱:        <input type="text" name="name" />        <label></label>        密碼:        <input type="text" name="password" />    </body></html>

 

使用jQuery發送非同步請求

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.