zoukankan      html  css  js  c++  java
  • 前台向后台传值的两种方法 以及 从后台获取数据的方法

    1、前台向后台传值方法一:

    表单提交的方式:

     1 <form action="${path }/manage/logon.do" method="post" id="logonForm">
     2   <table cellpadding="0" cellspacing="0" border="0">
     3     <tr height="50">
     4       <td>
     5         <input type="text"  id="userIdMark" name="userIdMark" />
     6         <input type="hidden"  id="userId" name="userId" />
     7       </td>
     8     </tr>
    15     <tr height="60">
    16       <td>
    17         <a href="#" id="logon" name="submit" class="login_btn"></a>
    18       </td>
    19     </tr>
    20   </table>
    21 </form>

    js代码:

    1 $("#logon").click(function(){
    2     $("#logonForm").submit();
    3 });

    2、前台向后台传值方法二ajax:

    1  <form id="myform" method="post" action="http://images.byshop.com/wechat/imgFormUpload" enctype="multipart/form-data">
    2       <input type="file" name="userfile[]"  multiple id="img_file">
    3       <input type="submit" value="shangchuan">
    4   </form>
    5   <input type="button" value="ajax_submit" onclick="imgFormUpload()">

    js代码:

      function imgFormUpload() {
             $.ajax({
                  dataType: 'json',
    url:
    http://images.byshop.com/wechat/imgFormUpload,
    success: function (data) {
    alert("submit success");
    }
    });
    }

    通过ajax从后台取值的方法,从后台获得值显示在列表中,如下图:

     1 <script type="text/javascript">
     2         $(function(){
     3            var Request = new Object();
     4             Request = GetRequest();
     5             var url;
     6             url = Request['vbillcode'];
     7              
     8             $.ajax({
     9                         type : 'POST',
    10                         url : "/rm/rmcsale/edit_specapplydetail",
    11                         data : {Listurl : url},
    12                         async:false,
    13                         success : function(data) {
    14                             console.log("----------- success-------------");
    15                              alert("您查询的订单号为:"+data.vbillcode);
    16                                $(".J-vbillcode").attr("value",data.vbillcode);
    17                                $(".J-billmaker").attr("value",data.billmaker);
    18                                $(".J-ctrantypeid").attr("value",data.ctrantypeid);
    19     
    20                         },
    21                         error : function(data) {
    22                              
    23                         },
    24                         dataType : 'json',
    25                          
    26                     });
    27              
    28              
    29          
    30         });
    31         </script>

    备注:靠自己也可以!依赖别人或者老师没有出路!

  • 相关阅读:
    UVa 12174 (滑动窗口) Shuffle
    UVa 1607 (二分) Gates
    CodeForces ZeptoLab Code Rush 2015
    HDU 1525 (博弈) Euclid's Game
    HDU 2147 (博弈) kiki's game
    UVa 11093 Just Finish it up
    UVa 10954 (Huffman 优先队列) Add All
    CodeForces Round #298 Div.2
    UVa 12627 (递归 计数 找规律) Erratic Expansion
    UVa 714 (二分) Copying Books
  • 原文地址:https://www.cnblogs.com/xu-blog/p/7118756.html
Copyright © 2011-2022 走看看