jquery load 方法回顯數據


使用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
    });
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM