Help me to see if there is any problem with ajax submission

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

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.