简体   繁体   English

通过AJAX将两个值传递给PHP文件

[英]Passing Two Values to PHP File Via AJAX

right now I'm successfully passing one value to a Bootstrap modal via AJAX, however when I attempt to pass a second value my code stops working. 现在,我已成功通过AJAX将一个值传递给Bootstrap模态,但是当我尝试传递第二个值时,我的代码停止工作。

JavaScript JavaScript的

function claimOrder(str, stre){
if (str=="") {
document.getElementById("txtH").innerHTML="Blank Order ID";
return;
}
if (stre=="") {
document.getElementById("txtH").innerHTML="Blank User ID";
return;
}

if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtH").innerHTML=xmlhttp.responseText;
}
}xmlhttp.open('GET','assignuser.php?q='+str'&w='+stre,true);
 xmlhttp.send();
}

Button That Triggers Function 触发功能的按钮

echo '<td><a data-toggle="modal" href="#mModal" onclick="claimOrder('.$order_id.', '.$activeuser.')" class="btn btn-success btn-lg">Claim</a></td></tr>';

Modal Called by Button 按钮调用的模态

<div class="modal fade" id="mModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div id="txtH"><b>Loading...</b></div>
</div><!-- /.modal -->

PHP PHP

<?php
$q = intval($_GET['q']);
$w = intval($_GET['w']);

etc... No changes were made to the PHP that worked before adding the second variable to the AJAX call except the extra line defining $w. 等等...在将第二个变量添加到AJAX调用之前,未对工作的PHP进行任何更改,除了定义$ w的额外行。 If I remove the extra parameter from the function and function call line assignuser.php runs fine and the modal is populated, so I'm pretty sure the problem is somewhere in the JavaScript. 如果我从函数中删除了多余的参数,并且函数调用行assignuser.php运行良好,并且填充了模态,那么我可以肯定问题出在JavaScript中。

You forgot a + in this portion of the code: 您在代码的这一部分忘记了+

xmlhttp.open('GET','assignuser.php?q='+str'&w='+stre,true);

So you will need to adjust it to: 因此,您需要将其调整为:

xmlhttp.open('GET','assignuser.php?q='+str+'&w='+stre,true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM