Ajax can be submitted to the background, the background can also get to the submitted data, the direct output can, but write some other processing code, can not output JSON
(document). Ready (function () { //post () mode $ (' #test_post '). Click (function () { $.post ( ' ajax.php '), { id:$ ("#id"). Val (), }, function (data) {//callback function var myjson= '; Eval (' myjson= ' + data + '; '); alert (data); $ (' #result '). HTML ("ID:" + myjson.username);});
$a = $_post["id"]; $conn = mysql_connect ("localhost", "root", ""); $my _db = mysql_select_db ("demo", $conn); $sql = "SELECT * from demo where id = $a"; $result = mysql_query ($sql, $conn); $userInfo = Mysql_fetch_assoc ($result); Print_r ($userInfo);// echo $a;
A direct output of $ A is possible, but the code executing the operation database cannot be output. Operation database code is correct, no problem
Reply to discussion (solution)
Look at the console, what's the tip?
Look at the console, what's the tip?
Without any hint
Assign the ID to a fixed value in ajax.php, open it separately ajax.php look, you should understand.
Assign the ID to a fixed value in ajax.php, open it separately ajax.php look, you should understand.
Yes, normal output. You mean Ajax didn't commit to the past? Should not ah, the front desk does not move, the backstage change to this can normal output
$a = $_post["id"]; Print_r ($a);
Assign the ID to a fixed value in ajax.php, open it separately ajax.php look, you should understand.
The problem has been found, not directly output, but to output a JSON array. Knot stickers. There's a part.