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");
    }
  }
}

Do you get any errors? Try wrapping your functions in

try { } catch(e) { alert(e); }

See if IE gives errors. I know IE sucks at error reporting.

Well, I have tried what you suggested and the error is.... "Object error"!!!
The register is added (which means that the 1st makeRequest is performed properly) but when in the makeRequest I call another makeRequest.... the error occurs!! Is there a way of doing it differently. I mean, first I add the register. THen if no error I sort it and show it. When I want to sort it, and call AJAX, I have the "Object error" error!
Thanks for your help.

Well, I have tried what you suggested and the error is.... "Object error"!!!
The register is added (which means that the 1st makeRequest is performed properly) but when in the makeRequest I call another makeRequest.... the error occurs!! Is there a way of doing it differently. I mean, first I add the register. THen if no error I sort it and show it. When I want to sort it, and call AJAX, I have the "Object error" error!
Thanks for your help.

Is the function alertContents1() defined?

Yes, alertContents1 is defined but it does not even execute it!.
I put an alert just before makeResquest(1,url) and it does not even fire!!

So the error happens in function alertContents()

Try putting some alerts in there to see just how far you go.

I believe, if you put:

window.onerror = function(err, url, line) { alert(err+' '+line+' '+url); };

anywhere in your js. Your should get the alert with the error msg and line numbers for uncaught exceptions.

Here is a bit on debugging in IE:
http://blogs.msdn.com/ie/archive/2004/10/26/247912.aspx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.