-------------------------------------jsonP跨域调用-------------------------------------
<div class="butom" value="提交">提交</div>
<script type="text/javascript">
$(".butom").click(function(){
$.ajax({
url:"http://localhost:5555/del1/del1.php",
type:"GET",
dataType:"jsonp",
jsonp:"callback",
success: function(data){
$.each(data,function(v,val){
console.log(v+"------>"+val);
})
},
error: function(){
alert("请求出错")
}
})
})
-----------------------------------------or___________________________________________________________________
$(".butom").click(function(){
creatScript();
})
function creatScript(){
var url="http://localhost:5555/del1/del1.php?callback=succ";
var script = document.createElement('script');
script.setAttribute('src', url);
// 把script标签加入head,此时调用开始
document.getElementsByTagName('head')[0].appendChild(script);
}
function succ(data){
alert(data.name)
}
</script>
<?php
$arr=array('name'=>'li','age'=>'22');
echo $_GET['callback']."(".json_encode($arr).")";
?>