我遇到了一个奇怪的问题,外部javascript文件函数跳过了windows.location。我的程序应该从表单中接收信息,然后创建、验证它,并在验证后使用get将其发送到一个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)
{
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),也可以是警示任何东西。事实上,它确实在后来的while(1)循环中工作,但几乎首先使浏览器崩溃。这就像它在做它应该做的事情之前离开了函数,并忘记了它。
我已经在firefox和google chrome中尝试过了,但这两种方法都不起作用。
还有,如果你找不到这样做的方法。如果你能给我一种方法,把表单中的值输入到javascript中,然后将有效的值发送到一个没有windows.location的php文件中(我已经尝试了我找到的所有其他变体,比如: windows.location.href location.href location.assign(url)),我将不胜感激。
顺便说一句,我省略的代码不会导致问题,因为它被注释掉了它不工作的地方,而在它工作的地方,它是不相关的,因为它工作,它只是发出了一个我不想要的警告。
发布于 2011-11-20 05:32:28
你应该打电话给我
window.location = url;不
windows.location = url;https://stackoverflow.com/questions/8197505
复制相似问题