For advice, thinkphp and jquery,ajax form verification

Source: Internet
Author: User

Figure 1

Figure 2

Figure 3

In the message input box in Figure 1 after entering the mailbox, through the JS file in Figure 2 to pass the mailbox information to the PHP file in Figure 3, figure 3 of the database operation is always error, no database operation Yes, do not know why

Reply content:

Figure 1

Figure 2

Figure 3

In the message input box in Figure 1 after entering the mailbox, through the JS file in Figure 2 to pass the mailbox information to the PHP file in Figure 3, figure 3 of the database operation is always error, no database operation Yes, do not know why

1. Use Ajaxreturn instead of Echo
2, True and false to return the result as a string, which is "true", "false"
3, the result of the return through Ajax is a string , can not be directly judged by the IF, but should use = = to judge, otherwise always for if (response) has always been true, so the return of the existing

=======================
Modify the answer
First you have to have a good understanding of the MVC model before you can use thinkphp correctly.
1, thinkphp logic is/controller/method,
Suppose your module name is index (it should look like this from your project directory)


  
   where($where)->find()){            $this->ajaxReturn(true);        }else{            $this->ajaxReturn(false);        }    }}

Then your post code should write this, the location should be in the Thinkphp view folder

$.post("/Login/verify",{loginEmail:loginEmail}, function(response){    ...}

Return results with Ajaxreturn

False and true replace with ' false ' and ' true ' try

$.post (URL, data, function, ' josn ')

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