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