Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Javascript / Client Side Development

Nesting AJAX


Is it possible to do this? Does AJAX allow one call to be made within
another?? So far I'm having problems. Below I've tried to simplify my
code into its basic elements - the problem I'm getting is that that
ResponseHandler1 is getting called fine from an intial call to
NestedAjaxCalls but ResponseHandler2 (the nested call) isn't. I've
tested out this very code to make sure!

      function NestedAjaxCalls() {
          var ajax_connection = createRequest();
          ajax_connection.open('get', 'request1.php');
          ajax_connection.onreadystatechange = function() {
            ResponseHandler1(ajax_connection);
          }
          ajax_connection.send(null);
      }

      function ResponseHandler1(ajax_connection) {
        var ajax_connection2 = createRequest();
        ajax_connection2.open('get', 'request2.php');
        ajax_connection2.onreadystatechange = function() {
          ResponseHandler2(ajax_connection);
        }
      }

      function ResponseHandler2(ajax_connection) {
        // Does not get called
        echo('Success! Nested AJAX call was made successfully.');
      }

      // create an AJAX Request
      function createRequest() {
        var ajaxRequest;

        try
        {
          ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        }
          catch (e1)
          {
            try
            {
              ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            }
              catch (e2)
              {
                ajaxRequest = new XMLHttpRequest();
              }
          }

        return ajaxRequest;
      }

Is it something simple I'm doing wrong like the scope of my connection
variables or is this a limitation with AJAX - if so could anyone
suggest an alternative method of doing the same thing? Any replies
gratefully received...

Cheers,
Steve

steve.chamb@gmail.com wrote:
> Is it possible to do this? Does AJAX allow one call to be made within
> another?? So far I'm having problems. Below I've tried to simplify my
> code into its basic elements - the problem I'm getting is that that
> ResponseHandler1 is getting called fine from an intial call to
> NestedAjaxCalls but ResponseHandler2 (the nested call) isn't. I've
> tested out this very code to make sure!

<snip code>

> Is it something simple I'm doing wrong like the scope of my connection
> variables or is this a limitation with AJAX - if so could anyone
> suggest an alternative method of doing the same thing? Any replies
> gratefully received...

I would suggest you take a look at Matt Kruse's http://www.ajaxtoolbox.com/

--
-Lost
Remove the extra words to reply by e-mail.  Don't e-mail me.  I am
kidding.  No I am not.

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc