Will the AJAX request value be returned after the page is refreshed?

Source: Internet
Author: User

Template

Controller

Model


I submit the form with $.post, if the login succeeds to save the information directly to the session, if the failure returns the reason of failure.
I wrote the form on the modal frame, and I showed the reason of failure on the modal frame. However, the modal box is automatically refreshed and closed when returned.
If I return false after $.post is finished, the modal box is not closed and the display is normal. However, if the login is correct, it will return false;
How to Resolve

Reply content:

Template

Controller

Model


I submit the form with $.post, if the login succeeds to save the information directly to the session, if the failure returns the reason of failure.
I wrote the form on the modal frame, and I showed the reason of failure on the modal frame. However, the modal box is automatically refreshed and closed when returned.
If I return false after $.post is finished, the modal box is not closed and the display is normal. However, if the login is correct, it will return false;
How to Resolve

<代码太长了…… 看了好纠结="">

If you are clear that you do not perform the reload operation in JS, however, clicking the Submit button will refresh the page:
When you click Submit, actually completed two actions, one is you write Ajax submission data, one is the form form automatic submission, and you in the form of the action is empty, it is submitted to the current page, that is, refresh
So you

click(function(){    //ajax提交    $.post();    return false;        })        

When you return false, it prevents the submission of the form, which can be added.

But you said the login normal is also return false you do not use him as a callback result, as an action, OK,
To see if the return is successful, just look at your Ajax return value OK, and then write the action in the AJAX callback if you need to do the following on the success of the login

You sent the server-side code, too.

Ajax sends a request to the server, the server can return a JSON result, the same can be redirected to refresh the page, depending on the server-side code implementation, LZ should first go to the server to troubleshoot

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