S
steve.chambers
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
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