I cannot figure this out. I am fairly new to this whole idea of passing data from javascript to php. I have a function that works most of the time, but when I remove an alert() statement in javascript, it fails. Here is my code:
Code:
function newtrans(mydept,myprice)
{
if (buffer) // Only store transactions with a dollar amount
{
getnewtransid();
//ajaxrequest.abort();
ajaxrequest.open("GET", storetransurl + 'id=21' + '&dept=' + escape(mydept) + '&price=' + escape(myprice), true);
ajaxrequest.onreadystatechange = handleHttpResponse;
ajaxrequest.send(null);
}
}
function getnewtransid()
{
ajaxrequest.open("GET", getnewtransurl + 'type=requestnew', true);
ajaxrequest.onreadystatechange = handleHttpResponse;
ajaxrequest.send(null);
[\code]
this next line is the issue, when I have it present, it executes without error (although I still don't get the value stored in newtransid like I need - the returned value from the xmlhttprequest).
[code]
alert(newtransid);
[\code]
[code]
}
function handleHttpResponse()
{
if (ajaxrequest.readyState == 4)
{
alert(ajaxrequest.responseText);
//alert(newtransid);
}
}
function createXMLHttpRequest()
{
var ua;
if(window.XMLHttpRequest)
{
try
{
ua = new XMLHttpRequest();
}
catch(e)
{
ua = false;
}
}
else if(window.ActiveXObject)
{
try
{
ua = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
ua = false;
}
}
return ua;
}
[\code]
I am hoping that someone will help me to understand two things:
1. Why removing an alert statement would cause a failure
2. What I need to do in order to store the value that comes back from the xmlhttprequest so that I can use it in other parts of the my javascript code.
Thanks,
LJ Wilson
LJ Wilson
My personal saying - Just remember, it can always get worse, and usually will.