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");
       }
    
    %>
  • 相关阅读:
    C#使用Selenium实现QQ空间数据抓取 说说抓取
    C#使用Selenium实现QQ空间数据抓取 登录QQ空间
    [bug系列]Method not found: 'Void Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommandBuilderFactory
    【原创】CA证书申请+IIS配置HTTPS+默认访问https路径
    【原创】MVC项目中使用JQuery的upladify图片上传插件相关问题的解决方案
    Jquery中$.ajax()方法参数详解
    开发IOS应用真的一定要买苹果电脑设备吗?
    vim全选内容命令
    配置jdk环境变量
    mysql联查中使用if和group by会让你的结果不是你想要的
  • 原文地址:https://www.cnblogs.com/jimorulang/p/5587843.html
Copyright © 2011-2022 走看看