Home > Web Front-end > JS Tutorial > Solution to JQuery.get submission page not jumping

Solution to JQuery.get submission page not jumping

韦小宝
Release: 2017-12-04 10:39:19
Original
2094 people have browsed it

In order to give the website a better experience for users, we usually use jquery for data interaction. This article talks about using jquery The solution to submit the page without jumping, let us take a look at jqueryHow to achieve the jump

Code demonstration:

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<script>
        window.location.host;
        $(document).ready(function () {
            $("#btnTestGet").click(function () {
                jQuery.get("About.aspx", { name: "alex" }, function () { alert("aaa")});
            });
        });
</script>
        <button id="btnTestGet" value="Test JQuery" >Test JQuery</button>
</asp:Content>
Copy after login

Problem Analysis:

Some Jquery tutorials say that you can jump using jquery.get(url,data,function(){}).

The above code does not jump. If there is an error in the middle, the callback function cannot be executed, but the above code is executed. What is the reason?

After analysis, we learned that jquery.get(url,data,function(){}) is an ajax method and will not jump.

If you want to jump, you need to function(){//Jump here;} in the callback function, because Ajax itself is to achieve asynchronous request for partial refresh, and of course it will not jump the page.

To jump to the frontend of the page, directly use document.Url="xx.aspx"; or window.location.href="xx.aspx"; has nothing to do with ajax. The correct ajax method is to obtain the backend in the callback function. The returned value is then used to operate the html attribute method to partially update the page.

In this way, the problem of jquery.get submission page not jumping is solved. This is a hassle.

Related recommendations:

Summary on the use of extend() in jQuery

jQuery loads an html page into the specified div

Detailed explanation of the problem of JQuery binding events in a loop

The above is the detailed content of Solution to JQuery.get submission page not jumping. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template