2011-10-10 51 views
0

我不明白我在上FF7window.location.href(VAR)在FF7奇怪的行爲

的問題,我有一個返回JSON對象(jQuery的)一個Ajax調用。

if(data.result=='ok') { 
    var url = baseURL + "azioni/makeForm/" + data.actcode + "/DIA/" + data.az_id; 
    console.log(url); 
    window.location.href(url); 
} 

不要在所有的工作,但是這一個作用:

if(data.result=='ok') { 
    var url = baseURL + "azioni/makeForm/" + data.actcode + "/DIA/" + data.az_id; 
    console.log(url); 
    window.location.href = 'http://www.google.com/'; 
    window.location.href(url); 
} 

爲什麼?

請注意,console.log完美工作,並輸出正確的網址!

回答

1

也許你可能要使用:

document.location.href = url; 

我覺得.href不是方法而是一個屬性,所以你只能給它分配一個值。下面可能是一個讓瀏覽器重定向到該位置的事件監聽器。

+0

哇,我是在b my我的頭,因爲一個非常愚蠢的錯誤,謝謝! – 0plus1

+0

沒問題...很高興我可以幫忙! –

0

window.location.href不是功能。在第二個例子中,你可以簡單地刪除window.location.href(url)和它的工作

2

也許嘗試:

if(data.result=='ok') { 
       var url = baseURL+"azioni/makeForm/"+data.actcode+"/DIA/"+data.az_id;console.log(url); 
       window.location.href = url; 

      } 
+0

據我所知window.location.href不是一個函數,所以你不需要() – Alex