【小编推荐】jquery ajax跨域模板代码

2015-08-06   |   发布者:梁国芳   |   查看:3320次

前端开发
 前台js:
        $.ajax({  
             type : "get",  
             async:false,  
             url : "http://192.168.1.77/shaizi/dice.php",  
             dataType : "jsonp",  
        
             success : function(json){  
        
 
 
var num1 = json[0];
var num2 = json[1];
diceroll(dice1,num1);//掷色子1动画
diceroll(dice2,num2);//掷色子2动画
var num = parseInt(num1)+parseInt(num2);
alert(num);
$("#msg").css("top","-10px").fadeIn(500).text(num+'点').animate({top:'-50px'},'1000').fadeOut(500);
roll(0, num); 
 
 
 
             },  
             error:function(){  
                 alert('fail');  
             }  
         }); 


后台:php
$b  =  json_encode($arr_a);
$jsonp_callback=$_GET['callback'];
echo $jsonp_callback.'('.$b.')';


需要的  只需要  复制上 改改代码即可。