2013-04-29 54 views
1

我有一個登錄表單,其中有兩個字段 - usernamepassword。 我正在使用ajax發送這個變量到login.php哪些工作。 現在我需要得到datalogin.php回來,我這樣做:ajax重定向不起作用

$.post('login.php',{username:username,password:password}, 
function(data) 
{ 
    $('#data').html(data); 
    if (data=='login'){ 
     window.location="http://www.google.co.uk"; 

    } 

}); 

的問題是,如果只有數據是== login但它不代碼應該重定向到http://www.google.co.uk 。請幫忙謝謝!

+0

嘗試'window.location.href' – phpisuber01 2013-04-29 10:56:00

+0

你得到的迴應是什麼 – bipen 2013-04-29 10:56:17

+0

爲什麼不使用header();功能 前。標題('Location:link'); – CaffeineShots 2013-04-29 11:22:54

回答

5

你錯過了href

window.location.href="http://www.google.co.uk"; 
+2

我不這麼認爲,它應該沒有href。嗯在html4。大約5 - 10年前...:D – inf3rno 2013-04-29 10:56:35

0

,如果你想重定向到一個新的頁面,您可以這樣寫。 window.open(http://www.google.co.uk,「_ parent」,「toolbar = no,location = no,directories = no,status = no,menubar = no,scrollbars = yes,resizable = yes,width = 1000,height = 850」);使用 window.open(http://www.google.co.uk,「_ blank」,「toolbar = no,location = no,directories = no,status = no,菜單欄= no,scrollbars = yes,resizable = yes,width = 1000,height = 850「);