Javascript windows.location,跳过
我一直遇到一个奇怪的问题,外部 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位置。 href 位置.分配(url)) 我将不胜感激。
顺便说一下,我遗漏的代码并没有引起问题,因为它在不起作用的地方被注释掉了,而在它起作用的地方则被注释掉了,因为它起作用了,它只是提出了一个我不想要的警报。
I have been having a strange problem with an external javascript file function skipping over windows.location. my program was supposed to take in information from forms then create validate it and after it was validated send it to a php file with get.
I simplified my code to look like
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);
}
}
and it didn't work.
Here is the real funny thing
when I include an alert at the end after windows.location it calls the php file. When I don't it doesn't.
for instance
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);
}
}
works but it has to print out the alert first. On the other hand when I don't have an alert after the windows.location call It doesn't work at all.(and I know it works with the alert because It is then redirected to the php file which I know works too).
It doesn't have to be alert(url) either It could be alert anything really. in fact it did work with a while(1) loop done afterward but almost crashed the browser first. It's like it is leaving the function before it does what it is supposed to and forgetting about it.
I have tried it in firefox and in google chrome without either way working.
also if you can't find a way to do this. if you could give me a way to take in values from a form to javascript and then send valid values to a php file without windows.location(i've tried every other variant I have found also like: windows.location.href location.href location.assign(url))
I would appreciate it.
by the way The code I left out is not causing the problem because it is commented out where it doesn't work and in the one where it works that is irrelevant because it works it just puts up an alert I don't want.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
应该打电话
你不
You should be calling
not