前臺向後臺傳值的兩種方法 以及 從後臺獲取數據的方法
阿新 • • 發佈:2017-07-04
list 獲取數據 data border asc req rip attr 訂單
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>
備註:靠自己也可以!依賴別人或者老師沒有出路!
前臺向後臺傳值的兩種方法 以及 從後臺獲取數據的方法