$.getjson get the value of PHP output

Source: Internet
Author: User
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 '));

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.