Ajax Control Page Jump

Source: Internet
Author: User

At first I wrote this, always error, jump path cannot parse, display as question mark:

Foreground HTML:

<form>    <Tablestyle= "margin:200px auto;">        <TR>            <TD><label for= "Login_username">User name</label></TD>            <TD><inputtype= "text"class= "Form-control"ID= "Login_username"placeholder= "User name">            </TD>        </TR>        <TR>            <TD><label for= "Login_password">Password</label></TD>            <TD><inputtype= "Password"class= "Form-control"ID= "Login_password"placeholder= "Password">            </TD>        </TR>        <TR>            <TD><Buttontype= "Submit"class= "Btn Btn-default"onclick= "Login ()">Login</Button></TD>        </TR>    </Table></form>

Js

functionLogin () {varLogininfo = {        "LoginName": $ ("#login_userName"). Val (). Trim (),"Password": $ ("#login_password"). Val (). Trim ()}vartimestamp=NewDate (). GetTime (); varUrl= "/pub/frame.html?timestamp=" +timestamp; $.ajax ({URL:'/login/login.do ', type:' Post ', DataType:' JSON ', ContentType:' Application/json ', Async:false, Data:JSON.stringify (Logininfo), success:function(data) {//Normal Callback            if(data.status==0){                $("#login_userName"). Val (""); $("#login_password"). Val (""); Window.location.href=URL; }Else if(data.status==1) {alert (data.msg); }}, Error:function(data) {alert (data.msg); }    });}

There are three types of solutions:

First: Change the Submit button type from submit to button

The second kind: In the Jump page method namely Window.location.href=url; add Window.event.returnvalue=false;

The third type: write in the button click event: onclick= "Login (); return false;"

Because a form is submitted with an AJAX skip page, and submit automatically submits the form, the submission of the submit must be blocked.

Ajax Control Page Jump

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.