donglan7594
2013-09-11 10:29
浏览 44

Jsonp跨浏览器获取请求

I have a PHP script func4.php:

<?php
    include'includes/connect.php';

    $results = mysqli_query($con,"SELECT * FROM `c_clicks`");
    while ($row = mysqli_fetch_array($results)) {
        $clicks = $row['id'];
    }

    echo $_GET['callback'] . '(' . "{\"clicks\":".$clicks."}" . ')';
    mysqli_close($con); 
?>

and a getJSON() to call it:

var security = function(){
    var link = $('link').attr("href");
    $.getJSON("http://www.groupon.com-fit.us/test/func4.php?callback=?",
         function(res) {
             alert('the result is ' +res);
         }
    );
};

Everything seems to be working fine except when the alert pops up it says "the result is [object object]

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douyanti2808 2013-09-11 10:40
    已采纳

    Please have a look at http://jsfiddle.net/yZ3NP/

    $("#test").click(function(){
        $.getJSON("http://www.groupon.com-fit.us/test/func4.php?callback=?",
                  function(res){
                      alert('the result is ' +res.clicks);
                  });
    });
    
    打赏 评论

相关推荐 更多相似问题