1

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.

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
$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. 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.

1 Answer 1

2

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);
Sign up to request clarification or add additional context in comments.

7 Comments

That's all it will take
Thank you, I've added the + but still no luck
When you output both values, are you getting any results?
Nope, if I replace the statement replacing the modal text with the response text with a statement outputting the values I get no results, as if the function wasn't running
Ahhh I believe the additional issue is that I was trying to pass a string to w, when the php code to handle is: $w = intval($_GET['w']); How should I edit this php to accept a string?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.