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"). html (v);
$ ("#mid"). Val (id);
},100);
Stop_btn.show ();
Start_btn.hide ();
}else{
$ ("#roll"). HTML ("The system cannot find a resource, 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 see if the JSON returned is correct, PHP is normal if correct, or PHP has a problem
2. If PHP is normal, then print out the JS JSON to see what's wrong.
1. Run PHP directly to see if the JSON returned is correct, PHP is normal if correct, or PHP has a problem
2. If PHP is normal, then print out the JS JSON to see what's wrong.
How to print out json, PHP normal
Echo Bin2Hex (file_get_contents (' http://localhost/data.php '));