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

jsonp

时间:2016-12-23 23:07:42      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:head   append   curl   tag   函数名   etop   默认   limit   sop   

1.动态创建js脚本

var js =document。createElement("script")

2.给脚本设置src

js.src="http://192.168.0.122/json.php?callback=xxx";

3. 把脚本添加到head

document。getElementByTagName("head")[0].appendChild(js);

4.实现回调函数

function xxx(a){

console.log(a);

}

$(function($){

$.ajax({

type:"get",

url:"http//192.168.0.122/jsop.php",

async:true,

dataType:"jsonp",

jsonp:"callback",//传递给请求页面的一个东西,用来获得jsonp回调函数的参数名(一般默认就是callback)

jsonpCallback:"filghtHandler",//回调函数名,默认情况下JQ会自动生成一个随机的函数名

success:function(res){

console.log(res);

}

});

});

error:function()

1.创建一个请求对象

$ch=curl_init();

2.绑定地址 setopt 设置请求参数

curl_setopt($ch,CURLOPT_URL, "http://api.dotaly.com/lol/api/v1/shipin/latest?author=xiaozhi&iap=0&ident=43643E2C-CF06-46E8-9AF2-50A255D268B2&jb=0&limit=50&offset=0&token=7e93a7124b25ee81971b4b2473222c0f");

curl_setopt($ch,CURLOPT_RETURNTRNTRANSFER,1);

3.开始请求  获取请求结果

$res=curl_exec($ch);

echo $res;

jsonp

标签:head   append   curl   tag   函数名   etop   默认   limit   sop   

原文地址:http://www.cnblogs.com/sanshao221/p/6216122.html

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