代码如下:
代码如下:
<%@ 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提交页面不跳转的问题,这个折腾啊。
如对本文有疑问, 点击进行留言回复!!
offset、client、scroll (width,height、left,top、X,Y)
网友评论