javascript - infinite loop when redirect - Stack Overflow

When redirect to my home page I have an infinite loop. For example isthen when redirect using javascr

When redirect to my home page I have an infinite loop. For example is then when redirect using javascript url = 'home/request_verification' ; window.location = url;

my url now bees then and so on. It always added home class.

I just used this script

function checkCookie() {
var mob_tel=getCookie("mob_tel");
if (mob_tel!=null && mob_tel!="") {
    //alert("Wele again " + mob_tel);
    url = "home/test";
    window.location = url;
    //window.location.href('home/checkbalance');
} else {
    set_name("");
}
}

then in my body

<body onload="checkCookie()">
 ...........
 ................
</body>

Help anyone..

When redirect to my home page I have an infinite loop. For example is http://mydomain. then when redirect using javascript url = 'home/request_verification' ; window.location = url;

my url now bees http://mydomain./home/request_verfication then http://mydomain./home/home/request_verification and so on. It always added home class.

I just used this script

function checkCookie() {
var mob_tel=getCookie("mob_tel");
if (mob_tel!=null && mob_tel!="") {
    //alert("Wele again " + mob_tel);
    url = "home/test";
    window.location = url;
    //window.location.href('home/checkbalance');
} else {
    set_name("");
}
}

then in my body

<body onload="checkCookie()">
 ...........
 ................
</body>

Help anyone..

Share Improve this question asked Feb 1, 2012 at 7:11 Wondering CoderWondering Coder 1,70211 gold badges31 silver badges51 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

home/test is a relative url. You're probably in need of an absolute url /home/test.

The difference is that home/ looks for home in the current folder, but /home looks for home in the root of your website.

You got to use the absolute path, else the infinite loop continues. So, use

url = "http://mydomain./home/test";
window.location = url;

If you do not want to hardcode the root URL ie.,http://mydomain., try getting the root directory of the site from the server side like $_SERVER["HTTP_HOST"] in PHP as shown below:

url = "http://"+"<?php echo $_SERVER['HTTP_HOST'];?>"+"/home/test"; (for localhost) and
url = "<?php echo $_SERVER['HTTP_HOST'];?>"+"/home/test"; (for urls already containing http://)

window.location = url;

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745413216a4626626.html

相关推荐

  • javascript - infinite loop when redirect - Stack Overflow

    When redirect to my home page I have an infinite loop. For example isthen when redirect using javascr

    4小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信