W
whadar
Hello all,
I need a replacement for xmlhttprequest activex cause I'm running
clients with no activex support.
The request should be POST and synchronous.
There are few implementations for xmlhttprequest out there, but from
what I saw they use GET and asynchronous events.
I am dynamically creating a form and submitting it to a hidden iframe.
The iframe is still in its "loading" state so i need to wait for it.
the problem is I cant use the onreadystate event cause I need the
function itself to return the response. So I tried setTimeout - Here's
the code:
var response = "";
function CallServer(xml, url) {
//remove previous form
if (document.forms.length > 0)
{
document.forms[0].removeNode(true);
response = ""
}
var formObj = document.createElement ("form");
formObj.innerHTML = "<input id=\"xmlRequest\" name=\"xmlRequest\"
type=\"text\" value=\"" + xml + "\" />";
window.document.appendChild(formObj)
formObj.action = url;
formObj.method = "post";
formObj.target = "ifrmSendData";
formObj.submit();
WaitForResponse();
return response;
}
function WaitForResponse()
{
if (ifrmSendData.frameElement.readyState == "complete")
{
response = ifrmSendData.document.body.innerText;
}
else
{
setTimeout("WaitForResponse()", 100);
}
}
Because setTimeout works asynchronously WaitForResponse does not
"wait", and simply return the default empty string...
Another thing i tried to do is a while loop that waits for readyState
== "complete" but that hangs the browser and the iframe is never
loaded.
How can I wait for the iframe to be loaded and then read the response?
If not possible, other alternatives for synchronous xmlhttprequest are
most welcome...
Thanks very much,
Hadar
I need a replacement for xmlhttprequest activex cause I'm running
clients with no activex support.
The request should be POST and synchronous.
There are few implementations for xmlhttprequest out there, but from
what I saw they use GET and asynchronous events.
I am dynamically creating a form and submitting it to a hidden iframe.
The iframe is still in its "loading" state so i need to wait for it.
the problem is I cant use the onreadystate event cause I need the
function itself to return the response. So I tried setTimeout - Here's
the code:
var response = "";
function CallServer(xml, url) {
//remove previous form
if (document.forms.length > 0)
{
document.forms[0].removeNode(true);
response = ""
}
var formObj = document.createElement ("form");
formObj.innerHTML = "<input id=\"xmlRequest\" name=\"xmlRequest\"
type=\"text\" value=\"" + xml + "\" />";
window.document.appendChild(formObj)
formObj.action = url;
formObj.method = "post";
formObj.target = "ifrmSendData";
formObj.submit();
WaitForResponse();
return response;
}
function WaitForResponse()
{
if (ifrmSendData.frameElement.readyState == "complete")
{
response = ifrmSendData.document.body.innerText;
}
else
{
setTimeout("WaitForResponse()", 100);
}
}
Because setTimeout works asynchronously WaitForResponse does not
"wait", and simply return the default empty string...
Another thing i tried to do is a while loop that waits for readyState
== "complete" but that hangs the browser and the iframe is never
loaded.
How can I wait for the iframe to be loaded and then read the response?
If not possible, other alternatives for synchronous xmlhttprequest are
most welcome...
Thanks very much,
Hadar