mrtechguy
01-03-2011, 01:00 PM
Hi All,
I have the below code in a website and I have tried to add in a "toolbox" with things to do to the transations, and I figured that instead of having 3 different ajax functions to handle the 3 different pages that could be called, I should be able to use if statements to determine which page to call and what to send in the query. All of the code works fine if I remove the if statements (and the 2nd section for the "toolbox" however if I put them back in the request that is sent to the server never had the value of "transid". The server receives this request and sends back a response, however I never get this response, or it is never rendered to the page (I have even tried forcing the PHP file to send back an output.
I can't for the life of me work out what is wrong with it, so is anyone able to make some suggestions as to why the following isn't working. The code is contained within the <head> tags.
Thanks
MTG
<script>
function callback(serverData, serverStatus) {
document.getElementById("transactionbox").innerHTML=serverData;
}
function submitForm(whereTo) {
var ajax;
try { ajax = new ActiveXObject('Msxml2.XMLHTTP'); }
catch (e)
{
try { ajax = new ActiveXObject('Microsoft.XMLHTTP'); }
catch (e2)
{
try { ajax = new XMLHttpRequest(); }
catch (e3) { ajax = false; }
}
}
ajax.onreadystatechange = function()
{
if(ajax.readyState == 4 || ajax.readyState=="complete")
{
callback(ajax.responseText, ajax.status);
if(whereTo=="additem") { // = becomes ==
document.getElementById('barcode').value="";
document.getElementById('barcode').focus();
document.getElementById('toolbox').style.display = "block";
}
}
}
var ajaxdata;
if(whereTo=="additem") {
ajaxdata = "barcode="+document.getElementById('barcode').value+"&transid="+document.getElementById('transid').value;
ajax.open("POST", "additem.php", true);
}
else if(whereTo=="toolbox") {
if(toolBox=="discount") {
ajaxdata = "mode=discount&transid="+transID;
ajax.open("POST", "toolbox.php", true);
}
}
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
ajax.send(ajaxdata);
}
</script>
I have the below code in a website and I have tried to add in a "toolbox" with things to do to the transations, and I figured that instead of having 3 different ajax functions to handle the 3 different pages that could be called, I should be able to use if statements to determine which page to call and what to send in the query. All of the code works fine if I remove the if statements (and the 2nd section for the "toolbox" however if I put them back in the request that is sent to the server never had the value of "transid". The server receives this request and sends back a response, however I never get this response, or it is never rendered to the page (I have even tried forcing the PHP file to send back an output.
I can't for the life of me work out what is wrong with it, so is anyone able to make some suggestions as to why the following isn't working. The code is contained within the <head> tags.
Thanks
MTG
<script>
function callback(serverData, serverStatus) {
document.getElementById("transactionbox").innerHTML=serverData;
}
function submitForm(whereTo) {
var ajax;
try { ajax = new ActiveXObject('Msxml2.XMLHTTP'); }
catch (e)
{
try { ajax = new ActiveXObject('Microsoft.XMLHTTP'); }
catch (e2)
{
try { ajax = new XMLHttpRequest(); }
catch (e3) { ajax = false; }
}
}
ajax.onreadystatechange = function()
{
if(ajax.readyState == 4 || ajax.readyState=="complete")
{
callback(ajax.responseText, ajax.status);
if(whereTo=="additem") { // = becomes ==
document.getElementById('barcode').value="";
document.getElementById('barcode').focus();
document.getElementById('toolbox').style.display = "block";
}
}
}
var ajaxdata;
if(whereTo=="additem") {
ajaxdata = "barcode="+document.getElementById('barcode').value+"&transid="+document.getElementById('transid').value;
ajax.open("POST", "additem.php", true);
}
else if(whereTo=="toolbox") {
if(toolBox=="discount") {
ajaxdata = "mode=discount&transid="+transID;
ajax.open("POST", "toolbox.php", true);
}
}
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
ajax.send(ajaxdata);
}
</script>