2011-11-19 30 views
0

我一直有與外部JavaScript文件功能跳過windows.location一個奇怪的問題。我的程序應該從表單中獲取信息,然後創建驗證並在驗證後將其發送到帶有get的php文件。的Javascript windows.location,跳過

我簡化我的代碼看起來像

function validation(){ 
var alerting;//receives from forms commented out 
alerting=""; 
var url="phpadd.php";//after this i would validate it and create the alert but all of that is commented out and irrelevant 
if(alerting==""||alerting==null) 
    { 
    windows.location=url; 
    } 
    else 
    { 
    alert(alerting); 
    } 
} 

,並沒有奏效。

這裏纔是真正的有趣的事情 當我包括windows.location它調用PHP文件之後結束的警報。當我不這樣做。 例如

function validation(){ 
var alerting;//receives from forms commented out 
alerting=""; 
var url="phpadd.php";//after this i would validate it and create the alert but all of that is commented out and irrelevant 
if(alerting==""||alerting==null) 
    {//I also create the code here to put values In the url but I commented them all out so this is my effective code. 
    windows.location=url; 
    alert(url); 
    } 
    else 
    { 
    alert(alerting); 
    } 
} 

的作品,但它必須先打印出警報。另一方面,當我在windows.location調用後沒有提示時,它根本不起作用(我知道它對警報有效,因爲它會被重定向到我知道工作的php文件) 。

它不必警惕(url)或者它可能會提醒任何事情。事實上,它確實在一段時間內完成了工作,但是幾乎使瀏覽器首先崩潰。就好像在它完成它應該做的事情並忘記它之前,它正在離開該功能。

我已經嘗試過在Firefox和谷歌鉻沒有任何方式工作。

如果你還不能找到一個方法來做到這一點。如果你可以給我一種方法來從表單獲取值到JavaScript,然後將有效值發送到一個沒有windows.location的php文件(我試過了我發現的其他所有變體,比如:windows.location.href location。 href location.assign(url)) 我將不勝感激。

的方式,因爲它已被註釋掉它不工作,在一個地方工作的不相干的,因爲它的工作原理,它只是提出了一個警告我不我離開了代碼不是造成問題的原因不想要。

+0

對不起這是我鍵入它進入該網站時,我把它放在我的代碼確實使用了window.location的一個錯誤。抱歉 – user1055728

回答

1

你應該叫

window.location = url; 

windows.location = url;