JQuery.get提交页面不跳转的解决方法
代码如下:
代码如下:
<%@ page title="home page" language="c#" masterpagefile="~/site.master" autoeventwireup="true"
codefile="default.x.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>
问题分析:
有些jquery 教程上说,使用jquery.get(url,data,function(){})可以跳转。
以上代码却没有跳转,如果中间有错误的话,不能执行回调函数的,但以上代码却执行了,原因何在?
经过分析得知,jquery.get(url,data,function(){})这个是ajax的方法,是不会跳转的。
要跳转的话,需要在回调函数里function(){//这里做跳转吧;}才行,因为ajax本身就是为了实现异步请求局部刷新,当然不会跳转页面。
跳转页面前台直接用document.url=”xx.aspx”;或window.location.href=”xx.aspx”;和ajax没有关系,正确的ajax做法是回调函数中获取后台返回的值,然后据此操作html属性方法,局部更新页面。
如此,便解决了jquery.get提交页面不跳转的问题,这个折腾啊。
下一篇: 熟悉LINUX系统
推荐阅读
-
destoon整合ucenter后注册页面不跳转的解决方法
-
jquery mobile页面跳转后样式丢失js失效的解决方法教程
-
ajax提交session超时跳转页面使用全局的方法来处理
-
destoon整合ucenter后注册页面不跳转的解决方法
-
vue从一个页面跳转到另一个页面并携带参数的解决方法
-
Ajax提交表单页面刷新很快的解决方法
-
微信支付wx.requestPayment成功回调函数success里的页面跳转不执行
-
form表单只提交数据而不进行页面跳转的解决方案
-
利用js对象将iframe数据缓存, 实现子页面跳转后, 返回时不丢失之前填写的数据
-
linux环境配置nginx导致页面不刷新的解决方法