我在点击按钮和进行一些验证后遇到重定向页面的问题。我已经尝试了多个解决方案并继续得到相同的结果,其中地址栏填充网址但没有重定向。如果我用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;
}
});
}
..........
.......
.....
答案 0 :(得分:0)
这是基于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;
}
});
}