jquery jsonp模版

 $.ajax({
    dataType: "jsonp",
    url: "http://www.b.com/b.php",
    jsonp: "callback",
    success: function(data) {
        $(".info").text("uid:" + data.uid + " name:" + data.name);
    }      
});
$callback = !empty($_GET['callback']) ? trim($_GET['callback']) : '';
 
if(!empty($callback)) {
    $data = json_encode(array(
        'uid' => 1,
        'name' => '测试',
    ));
     
    echo $callback."({$data});";
}

 

posted @ 2019-04-10 16:58  WhoAmMe  阅读(171)  评论(0编辑  收藏  举报