Home  >  Article  >  Backend Development  >  $.getJSON 获取不到php输出的值

$.getJSON 获取不到php输出的值

WBOY
WBOYOriginal
2016-06-20 12:41:54883browse

js代码:
start_btn.click(function(){
        $.getJSON("data.php",function(json){
            if (json){
                var len = json.length;
                _gogo = setInterval(function () {
                    var num = Math.floor(Math.random()*len);
                    var id = json[num].id;
                    var v = json[num].mobile;
                    $("#roll").html(v);
                    $("#mid").val(id);
                },100);
                stop_btn.show();
                start_btn.hide();
            }else{
                $("#roll").html("系统找不到资源,请先导入数据");
            }
        });
    });

php代码:
if($action == ""){ //读取数据,返回json
    $query = mysqli_query($conn,"select * from member where status = 0");
    while($row = mysqli_fetch_array($query)) {
        $arr[] = array(
            'id' => $row['id'],
            'mobile' => substr($row['mobile'], 0, 3) . "****" . substr($row['mobile'], -4, 4));
    }
    $j_arr = json_encode($arr);
    echo $j_arr;
}


回复讨论(解决方案)

1.先直接运行php,看看返回的json是否正确,如果正确则php正常,否则php有问题
2.如果php正常, 则把js的json打印出来,看看有什么错误。

1.先直接运行php,看看返回的json是否正确,如果正确则php正常,否则php有问题
2.如果php正常, 则把js的json打印出来,看看有什么错误。



怎么将json打印出来啊,php正常的

echo bin2hex(file_get_contents('http://localhost/data.php'));

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn