$. GetJSON cannot get the php output value. js code:
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" pai.html (v );
$ ("# Mid"). val (id );
},100 );
Stop_btn.show ();
Start_btn.hide ();
} Else {
$ ("# Roll" login .html ("The system cannot find resources. please import data first ");
}
});
});
Php code:
If ($ action = "") {// read data, return 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;
}
Reply to discussion (solution)
1. run php directly to check whether the returned json is correct. if the returned json is correct, php is normal. otherwise, php has a problem.
2. if php is normal, print the json of js to see if there are any errors.
1. run php directly to check whether the returned json is correct. if the returned json is correct, php is normal. otherwise, php has a problem.
2. if php is normal, print the json of js to see if there are any errors.
How can I print out json? php is normal.
Echo bin2hex (file_get_contents ('http: // localhost/data. php '));