標籤:data http char tin priority public cal 簡化 let
使用jQuery對象.load()方法load() 方法的作用是可以通過 AJAX 請求從伺服器載入資料,並把返回的資料直接放置到指定的元素中。該方法使用起來非常簡單,大大簡化了ajax開發文法 : jQuery對象 . load(url, param ,callback);url 訪問伺服器位址 param 發送給伺服器參數 callback 當正常返回後 執行回呼函數注意:如果 param存在,以POST方式請求, 如果param 不存在,以GET方式請求樣本1、基本使用<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><!-- 引入jquery開發包 --><script type="text/javascript" src="js/jquery-1.12.3.js"></script><meta http-equiv="content-type" content="text/html; charset=UTF-8"><script type="text/javascript"> function test() { //發送ajax請求,並將返回的響應結果直接賦給div $("#mydiv").load("servlet/test1",{"str":"你很好","str2":"你很壞"}); }</script></head><body> <button onclick="test();">點我</button> <div id="mydiv">初始內容</div></body></html>
2、callback使用<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><!-- 引入jquery開發包 --><script type="text/javascript" src="js/jquery-1.12.3.js"></script><meta http-equiv="content-type" content="text/html; charset=UTF-8"><script type="text/javascript"> function test() { //發送ajax請求,並將返回的響應結果直接賦給div $("#mydiv").load("servlet/test1",{"str":"你很好","str2":"你很壞"},function(data){ //回呼函數裡面的內容 alert(data); }); }</script></head><body> <button onclick="test();">點我</button> <div id="mydiv">初始內容</div></body></html>注意:回呼函數在load填充完資料了之後執行
項目代碼執行個體:
function loadLastInfo(detail){ $(‘#myform‘).form(‘load‘, { // 調用load方法把所選中的資料load到表單中,非常方便 customerCommisonType : detail.customerCommisonType, customerCommison : detail.customerCommison, otherPay : detail.otherPay, otherPay01 : detail.otherPay01, otherPay02 : detail.otherPay02, otherPay03 : detail.otherPay03, otherPay04 : detail.otherPay04, otherPay05 : detail.otherPay05, otherPay06 : detail.otherPay06, otherPay07 : detail.otherPay07, otherPay08 : detail.otherPay08, otherPay09 : detail.otherPay09, otherPay10 : detail.otherPay10, otherPay11 : detail.otherPay11, otherPay12 : detail.otherPay12, isAudit : detail.audit, isPriority : detail.isPriority, remarks : detail.remarks });}
jquery load 方法回顯資料