Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript-在window.location.href不工作的情况下将变量传递到php页面_Javascript_Php - Fatal编程技术网

Javascript-在window.location.href不工作的情况下将变量传递到php页面

Javascript-在window.location.href不工作的情况下将变量传递到php页面,javascript,php,Javascript,Php,js函数的某些部分: 并没有向数据库发送任何信息,我已经通过警报测试了t1、t2和t3,它们不是空的,任何解决方案,谢谢 else{ var t1=document.getElementById('t1')。值; var t2=document.getElementById('t2')。值; var t3=document.getElementById('t3')。值; window.location.href=“b1.php?t1=“+t1+”&t2=“+t2+”&t3=“+t3; 警惕(‘

js函数的某些部分: 并没有向数据库发送任何信息,我已经通过警报测试了t1、t2和t3,它们不是空的,任何解决方案,谢谢

else{
var t1=document.getElementById('t1')。值;
var t2=document.getElementById('t2')。值;
var t3=document.getElementById('t3')。值;
window.location.href=“b1.php?t1=“+t1+”&t2=“+t2+”&t3=“+t3;
警惕(‘成功’);
}
//b1.php

问题:未通过
GET
方法提交值

注意:首先我检查了Chrome中的代码,然后检查了Firefox中的代码。奇怪的是,在Firefox中,代码工作得非常完美,而在Chrome中,它根本不工作,在Internet Explorer中也不工作等等

解决方案: 然后我检查了,因为您可能正在提交提交上的值,所以您需要添加一个
事件.preventDefault()到您的代码

下面是我立即尝试和使用的代码:

<form action="home.php" onsubmit="redirect(event)">
<input type="text" id="t1">
<input type="text" id="t2">
<input type="text" id="t3">
<input type="submit" >
</form>

<script>

function redirect() {

var t1 = document.getElementById('t1').value;
          var t2 = document.getElementById('t2').value;
          var t3 = document.getElementById('t3').value;
          event.preventDefault();
          alert( 'success' ); 
          window.location.href = "b1.php?t1=" + t1+ "&t2=" + t2 + "&t3=" + t3 ;


}

</script>

函数重定向(){
var t1=document.getElementById('t1')。值;
var t2=document.getElementById('t2')。值;
var t3=document.getElementById('t3')。值;
event.preventDefault();
警惕(‘成功’);
window.location.href=“b1.php?t1=“+t1+”&t2=“+t2+”&t3=“+t3;
}

问题:未通过
GET
方法提交值

注意:首先我检查了Chrome中的代码,然后检查了Firefox中的代码。奇怪的是,在Firefox中,代码工作得非常完美,而在Chrome中,它根本不工作,在Internet Explorer中也不工作等等

解决方案: 然后我检查了,因为您可能正在提交提交上的值,所以您需要添加一个
事件.preventDefault()到您的代码

下面是我立即尝试和使用的代码:

<form action="home.php" onsubmit="redirect(event)">
<input type="text" id="t1">
<input type="text" id="t2">
<input type="text" id="t3">
<input type="submit" >
</form>

<script>

function redirect() {

var t1 = document.getElementById('t1').value;
          var t2 = document.getElementById('t2').value;
          var t3 = document.getElementById('t3').value;
          event.preventDefault();
          alert( 'success' ); 
          window.location.href = "b1.php?t1=" + t1+ "&t2=" + t2 + "&t3=" + t3 ;


}

</script>

函数重定向(){
var t1=document.getElementById('t1')。值;
var t2=document.getElementById('t2')。值;
var t3=document.getElementById('t3')。值;
event.preventDefault();
警惕(‘成功’);
window.location.href=“b1.php?t1=“+t1+”&t2=“+t2+”&t3=“+t3;
}


code>$\u为您获得了什么输出?
window.location=“www.yourwebsite.com/b1.php?t1=“+t1+”&t2=“+t2+”&t3=“+t3
@king bia:当您使用
GET
方法将数据传递到php页面时,您可以正确地看到这些值是否在URL中传递???那么它们是否通过了?您很容易受到@ShahKhalid的攻击:请确保在url的开头也包含
http://
,否则它将被视为您当前域链接下的目录。。!
$\u为您获得了什么输出?
window.location=“www.yourwebsite.com/b1.php?t1=“+t1+”&t2=“+t2+”&t3=“+t3
@king bia:当您使用
GET
方法将数据传递到php页面时,您可以正确地看到这些值是否在URL中传递???那么它们是否通过了?您很容易受到@ShahKhalid的攻击:请确保在url的开头也包含
http://
,否则它将被视为您当前域链接下的目录。。!如果不是这样的话,那么用你的全部代码更新你的问题,你到底是如何提交这些值的,即使是在第一个地方,因为你刚刚共享了JS代码的
else
部分。。!您需要将函数调用为
onsubmit=“redirect(event)”
。有些浏览器不将
事件
作为全局变量提供。@Barmar:你的意思是这就是为什么它一开始不工作的原因,因为它现在工作时没有使用带有重定向功能的事件??不,我的意思是你需要修复它,这个答案才是正确的。你的代码在某些浏览器中可以工作,但不是其他人。如果不是这样的话,那么用你的全部代码更新你的问题,你到底是如何提交这些值的,即使是在第一个地方,因为你刚刚共享了JS代码的一部分。。!您需要将函数调用为
onsubmit=“redirect(event)”
。有些浏览器不将
事件
作为全局变量提供。@Barmar:你的意思是这就是为什么它一开始不工作的原因,因为它现在工作时没有使用带有重定向功能的事件??不,我的意思是你需要修复它,这个答案才是正确的。你的代码在某些浏览器中工作,但在其他浏览器中不工作。