Ajax submission, the background can't write code

Source: Internet
Author: User
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.
  • 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.