Help me see what's wrong with Ajax submissions.

Source: Internet
Author: User
  $.ajax ({                type: "Post",                URL: "nodedo.php",                Data: $ ("#form1"). Serialize (),                success:function (data) {                    layer.msg (' Add succeeded ', 2, 1);                },                error:function (data) {                           layer.msg (' Add failed ', 2, 2);                    alert (data);                }            })

Background
$conn  = mysql_connect ("localhost", "root", ""), $my _db = mysql_select_db ("Lyq", $conn);      $account = $_post[' account '];   $sql = "INSERT into salesman [account] values (' $account ')";      $result = mysql_query ($sql, $conn);     $userInfo = Mysql_fetch_assoc ($result);       echo  Json_encode ($userInfo);


There is also an AJAX submission
$.post (                ' nodedo.php ',                {                    account:$ ("#account"). Val (),                    name:$ ("#name"). Val ()                    //   name:$ (" #name "). Val ()                }, function                (data) {//callback function                    var myjson= ';                    Eval (' myjson= ' + data + '; ');                    alert (data);                }        );

Which part of this is wrong?


Reply to discussion (solution)

Alert (data)
Just look.

Alert (data)
Just look.


Data is empty

Where's the problem?
Speak clearly about the symptoms and look for problems.

Where's the problem?
Speak clearly about the symptoms and look for problems.


I don't know what's wrong, there's no change in the database, no return value.

Where are you alert (data)?


Where's the problem?
Speak clearly about the symptoms and look for problems.


I don't know what's wrong, there's no change in the database, no return value.


Then you can follow up and see if there are any statements that could be executed into the database insert, and if so, see what the statement is and whether it will execute correctly.

Where are you alert (data)?


When you get the return value



Where's the problem?
Speak clearly about the symptoms and look for problems.


I don't know what's wrong, there's no change in the database, no return value.


Then you can follow up and see if there are any statements that could be executed into the database insert, and if so, see what the statement is and whether it will execute correctly.


No tracking, hey.

You're in nodedo.php.
Print_r ($_post);

You're in nodedo.php.
Print_r ($_post);


Found the problem, the original submit button must be placed outside the form

That's not necessarily it!
1. Form onsubmit= ' return False '
2. Input Type=button value= ' Submit '
are not submitted by the form

  • 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.