Hello,
I have a js function that calls a AJAX function. Then, if the return code is correct, another AJAX function is called. It works perfectly with Mozilla but I am having a problem with Explorer... the 2nd AJAX call is not performed!!!
I have put an alarm after the command: http_request.open('GET', url, true); alert("AFTER OPEN"); http_request.send(null);
WIth Mozilla the alarm is fired but not with EXPLORER.
Could you tell me what is wrong please?
It seems that if a http_request.open is done, a second one cannot be done.
Thanks a lot
Here is part of the code. I don't know a lot about AJAX so I'm sure the solution will be easy for you to find:
First the makeRequest(0,url) command is executed... then the following line is executed: http_request.onreadystatechange = alertContents;
The alertContents function then calls makeRequest(1,url)... This is when the problem happens!!
Could you help!
..
function add()
{
// Add the address
//-----------------------
target=1;
myRand=parseInt(Math.random()*99999999); // cache buster
var url="addVlr.jsp?rand="+myRand+"&vlrAddress="+new_vlr_address;
[B]makeRequest(0,url);[/B]
}
...
function makeRequest(option,url)
{
http_request = false;
if (window.XMLHttpRequest) // Mozilla, Safari,...
{
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType)
{
http_request.overrideMimeType('text/xml');
}
}
else
{
if (window.ActiveXObject) // IE
{
try
{
http_request = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {}
}
}
}
if (!http_request)
{
alert('Giving up. Cannot connect.');
return false;
}
if (option == 0)
{
http_request.onreadystatechange = alertContents;
}
else
{
http_request.onreadystatechange = alertContents1;
}
[B]http_request.open('GET', url, true);
alert("AFTER OPEN");
http_request.send(null);[/B]
}
function alertContents()
{
if (http_request.readyState == 4) // COMPLETE
{
if (http_request.status == 200)
{
var values = http_request.responseText;
ier=trim(values);
if (ier !=0)
{
alert(ier);
}
else
{
// Treatment goes here
....
if (target == 1)
{
// Add address to array and sort it
//---------------------------------
myRand=parseInt(Math.random()*99999999);
var vlr_list=document.forms[1].vlr.value;
var url="sortVlr.jsp?rand="+myRand+"&vlrList="+vlr_list+"&vlrAddress=
"+new_vlr_address;
document.forms[1].vlr_addr.value="";
[B] makeRequest(1,url);[/B]
}
}
}
else
{
alert("Problem");
}
}
}