Help me to see if there is any problem with ajax submission
$. Ajax ({type: "post", url: "nodedo. php ", data: $ (" # form1 "). serialize (), success: function (data) {layer. msg ('added successfully', 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 commit
$. Post ('nodedo. php', {account: $ ("# account "). val (), name: $ ("# name "). val () // name: $ ("# name "). val ()}, function (data) {// callback function var myjson = ''; eval ('myjson = '+ data + ';'); alert (data );});
Which of the following is wrong?
Reply to discussion (solution)
Alert (data)
You can see it.
Alert (data)
You can see it.
Data is empty
What's wrong?
Clearly explain the symptoms and find the problem.
What's wrong?
Clearly explain the symptoms and find the problem.
I don't know what went wrong, the database didn't change, and there was no return value.
Where are you from alert (data?
What's wrong?
Clearly explain the symptoms and find the problem.
I don't know what went wrong, the database didn't change, and there was no return value.
Then you can trace and see if there are statements that failed to be inserted into the database. if so, you can see what the statements are and whether they can be correctly executed.
Where are you from alert (data?
When obtaining the return value
What's wrong?
Clearly explain the symptoms and find the problem.
I don't know what went wrong, the database didn't change, and there was no return value.
Then you can trace and see if there are statements that failed to be inserted into the database. if so, you can see what the statements are and whether they can be correctly executed.
Will not be tracked, hey
You are in nodedo. php
Print_r ($ _ POST );
You are in nodedo. php
Print_r ($ _ POST );
The problem is found. The original submit button must be placed outside the form.
Not necessarily!
1. form onsubmit = 'return false'
2. input type = button value = 'submit'
No form submission.