笨小孩做开发

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理


续上篇,加两个实用功能

1,增加data属性,请求参数
2,增加scope属性,可以让回调函数在指定的上下文中执行

 

接口如下

1
2
3
4
5
6
Sjax.load(url, {
    data        // 请求参数 (键值对字符串或js对象)
    success     // 成功后回调函数
    scope       // 回调函数执行上下文
    timestamp   // 是否加时间戳
});

 

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <title>sjax_0.2.js by snandy</title>
    <script src="https://files.cnblogs.com/snandy/sjax_0.2.js"></script>
</head>
<body>
<input type="button" value="Get Name" onclick="clk()"/>
<script type="text/javascript">
    function clk(){
        Sjax.load('https://files.cnblogs.com/snandy/jsonp.js', {
            fn : function(){alert(jsonp.name)},
            data : {a:'1',b:'2',c:[11,22]},
            timestamp : true
        });
    }
</script>
</body>
</html>


https://github.com/snandy/io

posted on 2016-03-31 14:38  笨小孩做开发  阅读(154)  评论(0编辑  收藏  举报