---
title: "跨域请求之JSONP 二"
author: "zhouyrt"
date: "2011-08-14T08:25:43Z"
tags: []
categories: ["Web前端"]
slug: "jsonp"
draft: false
lastmod: "2011-08-14T08:28:03Z"
id: 1148822
url: "https://snandy.iteye.com/blog/1148822"
---

续上篇，加两个实用功能

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

 

接口如下

 

 

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

 

 

示例

 

```
<!DOCTYPE HTML>
<html> 
<head> 
	<meta charset="utf-8"> 
	<title>sjax_0.2.js by snandy</title>
	<script src="http://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('http://files.cnblogs.com/snandy/jsonp.js', {
			fn : function(){alert(jsonp.name)},
			data : {a:'1',b:'2',c:[11,22]},
			timestamp : true
		});
	}
</script>
</body>
</html>
```