zoukankan      html  css  js  c++  java
  • jquery 提交数据

    目录 jquery ajax的应用

    1 表单提交

    2 ajax的提交(ajax post get)

    普通的表单提交

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    
    <%    
    String path = request.getContextPath();    
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";    
    pageContext.setAttribute("basePath",basePath);    
    %>    
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <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">
      </head>
      
    <!--  <script src="js/jquery_1.83min.js"></script>-->
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
      <body>
        <div>
        <form id="form1" action="" >
                <input type="text" name="username"><br>
                <input type="text" name="password"><br>
                <input type="button" value="登录" id="but1">
        </form>
        </div>
        <script type="text/javascript">
        $('#but1').click(function(){
        $('#form1').attr({'action':"${pageScope.basePath}login",'method':"post"}).submit();
        });
        </script>
    </html>

    $.ajax

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    
    <%    
    String path = request.getContextPath();    
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";    
    pageContext.setAttribute("basePath",basePath);    
    %>    
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <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">
      </head>
      
    <!--  <script src="js/jquery_1.83min.js"></script>-->
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
      <body>
        <div>
        <form id="form1" action="" >
                <input type="text" name="username"><br>
                <input type="text" name="password"><br>
                <input type="button" value="登录" id="but1">
        </form>
        </div>
        <script type="text/javascript">
        $('#but1').click(function(){
            var user={username:"sunfan",password:'helloworld'};
            $.ajax({
                url:"login", //访问地址--action地址
                type:"post", //提交方式
                data:user,   //提交给服务器的数据
                success:function(reData){ //回调函数的处理方式
                alert(reData);
                }
            });
        });
        </script>
    </html>

    $.post

    $('#but1').click(function(){
            var user={username:"sunfan",password:'helloworld'};
               $.post( //提交方式
                  "login", //访问地址
                  user,   //提交给服务器的数据
                  function(reData){//回调函数的处理方式
                  alert(reData);
                  }
               );
        });
    

    $.get与post类似只是提交的方式不同

        $('#but1').click(function(){
            var user={username:"sunfan",password:'helloworld'};
               $.get(
                  "login",
                  user,
                  function(reData){
                  alert(reData);
                  }
               );
        });
  • 相关阅读:
    jQuery的简单函数
    Playwright-录制脚本进行自动化测试
    使用requests爬取图片并下载
    使用jmeter对websocket进行性能测试
    selenium定位动态元素的2种情况
    Python-Faker
    关于css中@media的基本使用方法
    selenium-浏览器窗口最大化、刷新、前进、后退
    selenium-滚动条滑动,iframe切换,切换窗口
    jmeter-阶梯式压测
  • 原文地址:https://www.cnblogs.com/sunfan1988/p/3575670.html
Copyright © 2011-2022 走看看