zoukankan      html  css  js  c++  java
  • ajax实现异步刷新

    login.jsp

    <%@ 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>
            <base href="<%=basePath%>">
    
            <title>My JSP 'login.jsp' starting page</title>
    
            <meta http-equiv="pragma" content="no-cache">
            <meta http-equiv="cache-control" content="no-cache">
            <meta http-equiv="expires" content="0">
            <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
            <meta http-equiv="description" content="This is my page">
            <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->
    
            <script type="text/javascript" src="js/jquery-1.8.3.js">
    </script>
        </head>
        <script type="text/javascript">
    方法一
    function chkName() { var name = $("#username").val(); //alert(name); $.ajax( { url : "server.jsp", data : "name=" + name, //发送数据 dataType : "text", //响应数据类型 type : "get", //请求发方式 success : function(value) { //成功之后 if ($.trim(value) == "true") { $("#msg").html("用户已存在!"); } else { $("#msg").html("此用户可用!"); } } }); } </script>
    方法二

    <script type="text/javascript">
    function chkName() {
    var name = $("#username").val();
    $.get("server.jsp","name="+name,function(value){
    if ($.trim(value) == "true") {
    $("#msg").html("用户已存在!");
    } else {
    $("#msg").html("此用户可用!");
    }
    })
    }
    </script>

    方法三

    <script type="text/javascript">
    function chkName() {
    var name = $("#username").val();
    $.post("server.jsp","name="+name,function(value){
    if ($.trim(value) == "true") {
    $("#msg").html("用户已存在!");
    } else {
    $("#msg").html("此用户可用!");
    }
    })
    }
    </script>

    方法四

    <script type="text/javascript">
    function chkName() {
    var name = $("#username").val();
    $("#msg").load("server.jsp","name=" + name, function(value) {
    //alert();
    if ($.trim(value) == "true") {
    $("#msg").html("用户已存在!");
    } else {
    $("#msg").html("此用户可用!");
    }
    });
    }
    </script>



    <body> <form action="login.action" method="post"> <div> 用户名: <input name="username" type="text" value="" id="username" onblur="chkName()" /> <span id="msg"></span> </div> <input type="submit" value="提交" /> </form> </body> </html>

    server.jsp

    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
    
    <%
       String name=request.getParameter("name");
       if("sa".equals(name)){
         out.print("true");
       }else{
         out.print("false");
       }
    
    %>
  • 相关阅读:
    php远程图片抓取存放到本地路径并生成缩略图
    Linux下cron的使用
    centos6.3编译安装Apache2.4.3+PHP5.4.8+Mysql5.5.8
    CentOS 6.3 安装以及配置Apache php mysql
    用avalon和jquery做基础网页导航
    javascrip基本概念(三)
    grunt学习笔记(一)
    前端项目目录管理-部署结构
    javascript基本概念(二)
    avalon学习笔记ui篇-如何将avalon默认的amd模型禁止,以及用require重写。
  • 原文地址:https://www.cnblogs.com/jimorulang/p/5587843.html
Copyright © 2011-2022 走看看