码迷,mamicode.com
首页 > Web开发 > 详细

jquery load 方法回显数据

时间:2017-02-19 15:39:31      阅读:313      评论:0      收藏:0      [点我收藏+]

标签: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 方法回显数据

标签:data   http   char   tin   priority   public   cal   简化   let   

原文地址:http://www.cnblogs.com/mr-wuxiansheng/p/6415766.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!