function myJsonp(url, data, callback) { //参数判断
if (Object.prototype.toString.call(data) == "[object Function]") {
callback = data;
data = undefined;
} //设置回调函数随机名称
var cbFnName = "cb_" + Math.floor(Math.random() * 123456789).toString(32);
this[cbFnName] = callback; //将data对象格式转换为aaa=bbb&ccc=ddd格式
var stringIfyData = data != undefined ? Object.keys(data).map(function (key) {
return encodeURIComponent(key) + "=" + encodeURIComponent(data[key]);
}).join("&") + "&" : ""; //生成script标签
var scriptElement = document.createElement("script");
scriptElement.src = url + (url.indexOf('?') > -1 ? '&' : '?') + stringIfyData + "callback=" + cbFnName;
document.body.appendChild(scriptElement);
} //调用豆瓣api-三个参数
myJsonp("http://api.douban.com/v2/movie/top250", {name: "leyi"}, function (rps) {
console.info("rps", rps);
}); //调用豆瓣api-两个参数
myJsonp("http://api.douban.com/v2/movie/top250", function (rps) {
console.info("rps", rps);
});