JS页面重定向未触发
JS page redirect not firing
我在单击按钮和一些验证后无法重定向页面。 我已经尝试了多种解决方案,并不断得到相同的结果,其中地址栏填充了 URL,但没有重定向。 如果我使用 F5 刷新或单击浏览器的刷新按钮,它就可以工作,页面重定向和加载正常。 这是我尝试过的所有浏览器。所以我一定错过了什么或做错了什么。下面是我的代码:
........
..............
//render function for json + templates like handlebars, xml + xslt etc.
render: function (dataItem, statuses) {
$list.html(template(dataItem.content));
// action button events
//$('.action a').on("click",function (e){
$('.action a').bind('click', function(e){
var $this = $(this),
action = $this.attr("action"),
$id = $this.closest('ul').attr('id');
// get which link was click for appropriate action
switch(action){
case 'prev' :
break;;
case 'edit' :
if($this.hasClass("actionEnabled")) {
$().ajaxCall(checkURL,{'ID':$id})
.done(function(data){
if(data.result == 0) {
var baseURL = window.location.href.replace(window.location.hash, '') + '#',
url = baseURL + secondUrl_part + "?ID=" + $id;
// url = "http://mysite/index.php#/page/destPage.php?ID=idabcdefgh"
// tried with javascript all these different methods -> still did not work
// method 1
$(location).attr('href', "http://mysite/index.php#/page/destPage.php?ID=idabcdefgh");
// method 2
window.location = "http://mysite/index.php#/page/destPage.php?ID=idabcdefgh";
// method 3
window.location.href = "http://mysite/index.php#/page/destPage.php?ID=idabcdefgh";
// method 4
window.location.replace("http://mysite/index.php#/page/destPage.php?ID=idabcdefgh");
// even tried with return false as suggested by some people
//return false;
} else {
// todo error message no longer exist
}
})
.fail(function(){
// todo error : could not be loaded
})
} else {
e.preventDefault();
// to do add message cannot edit
}
break;;
case 'del' :
break;
}
});
}
..........
.......
.....
这是基于Ivan的答案的代码
//render function for json + templates like handlebars, xml + xslt etc.
render: function (dataItem, statuses) {
$list.html(template(dataItem.content));
// action button events
//$('.action a').on("click",function (e){
$('.action a').bind('click', function(e){
var $this = $(this),
action = $this.attr("action"),
$id = $this.closest('ul').attr('id');
// get which link was click for appropriate action
switch(action){
case 'prev' :
break;;
case 'edit' :
if($this.hasClass("actionEnabled")) {
$().ajaxCall(checkURL,{'ID':$id})
.done(function(data){
if(data.result == 0) {
var baseURL = window.location.href.replace(window.location.hash, '') + '#',
url = baseURL + secondUrl_part + "?ID=" + $id;
$(location).attr('href', url);
location.reload();
} else {
// todo error message no longer exist
}
})
.fail(function(){
// todo error : could not be loaded
})
} else {
e.preventDefault();
// to do add message cannot edit
}
break;;
case 'del' :
break;
}
});
}
相关文章:
- 角度 JS + 重定向不起作用
- node.js重定向无法添加用户名
- 将重定向URL链接添加到JS函数
- 节点JS重定向循环
- 查看完某个页面后,在重定向的页面上弹出js模式
- jQuery/JS获胜't在表单验证后重定向
- 重定向不带哈希的URL-Ember.JS
- 重定向到Angular JS中的另一个HTML页面
- 如何在使用Passport.js和Sails.js注册后重定向到特定位置
- 在angular.js中定义动态URL的重定向
- 在php中htaccess重定向url后,无法加载css和js
- Meteor JS Router.go重定向到同一页面
- Hapi-js重定向到另一个带有额外请求数据的路由
- 使用来自不同页面的cookie创建URL,并使用JS重定向
- Backbone.js路由器和Internet Explorer重定向问题
- Ember.js:如果控制器中满足某些条件,则在路由器中重定向
- 意思是.js - 登录后重定向用户 - 在本地工作,但在部署时不起作用
- 带有post值的JS jQuery重定向,不带<表单>
- 如何使用基于引用的Javascript重定向js文件
- 多站点重定向JS