亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

基于Jquery的跨域傳輸數(shù)據(jù)(JSONP)

 更新時(shí)間:2011年03月10日 13:02:32   作者:  
基于Jquery的跨域傳輸數(shù)據(jù)(JSONP) ,需要的朋友可以參考下。
后端:
復(fù)制代碼 代碼如下:

<?php
$json_str = json_encode(array("ddd"=>"11111111"));
echo $_GET['ja'].'('.$json_str.')';
?>

前端:
復(fù)制代碼 代碼如下:

$.getJSON('http://www.liushan.cn/test.php?ja=?',function (json){
alert(json);
});

純JS實(shí)現(xiàn)(JSONP):
復(fù)制代碼 代碼如下:

//server return aa({'ddd':'ddd'}) callback function name: $_GET['callback']
//author:lonely
(function(w){
function getjson(){}
getjson.prototype.set=function(url,callback,callbackname){
this.callfn=callbackname||'urlcallback';
this.url=url+"?callback="+this.callfn;
try{
eval(this.callfn+"=function(data){\n"+
"callback(data);\n"+
'delete '+this.callfn+';}');
}catch(e){return;}
this.request();
delete this.url;
}
getjson.prototype.request=function(){
var script=document.createElement("script");
script.src=this.url;
var load=false;
script.onload = script.onreadystatechange = function() {
if(this.readyState === "loaded" || this.readyState === "complete"){
load=true;
script.onload = script.onreadystatechange=null;
}
};
var head=document.getElementsByTagName("head")[0];
head.insertBefore(script,head.firstChild);
}
w.getjson=getjson;
})(window)
//使用DOME
new getjson().set("http://www.test.cn/test.php",function(data){
alert(data.ddd);
});

另一個(gè):getScript
復(fù)制代碼 代碼如下:

jQuery.getScript("http://dev.jquery.com/view/trunk/plugins/color/jquery.color.js", function(){
$("#go").click(function(){
$(".block").animate( { backgroundColor: 'pink' }, 1000)
.animate( { backgroundColor: 'blue' }, 1000);
});
});//CHM幫助文件示例

相關(guān)文章

最新評(píng)論