Hello,
I'm encountering an AJAX problem when I try to execute multiple AJAX requests at the same time. What I want to do is delete a message and display the status (succes or failure) of that in div1, and refresh the messages on the page in div2. This needs (for as far as my knowledge reaches) two AJAX actions from which I both need the responseText.
The problem
What happens when I execute my script is that the second action (refresh a part of the page) happens before the deletion is executed. The result of this is that when the deletion has been executed, the page is already updated, and the deleted message is still there.
The script
What I now have is:
[code=javascript]
function doAjax(url, element_id, img_url)
{
var ajaxObject = createAjaxObjec t();
ajaxObject.open ('GET', url, true);
ajaxObject.onre adystatechange = function()
{
if(ajaxObject.r eadyState==4 && ajaxObject.stat us==200)
{
document.getEle mentById(elemen t_id).innerHTML = ajaxObject.resp onseText;
delete ajaxObject;
}
else
{
if(img_url)
document.getEle mentById(elemen t_id).innerHTML = '<img src="' + img_url + '" alt=""/>';
}
};
ajaxObject.send ();
}
[/code]
to execute the actions, and
[code=javascript]
function createAjaxObjec t()
{
var ajaxObject;
try
{
ajaxObject = new XMLHttpRequest( );
}
catch (e)
{
try
{
ajaxObject = new ActiveXObject(" Microsoft.XMLHT TP");
}
catch (e)
{
try
{
ajaxObject = new ActiveXObject(" Msxml2.XMLHTTP" );
}
catch (e)
{
return;
}
}
}
return ajaxObject;
}
[/code]
to create the AJAX object.
I'm encountering an AJAX problem when I try to execute multiple AJAX requests at the same time. What I want to do is delete a message and display the status (succes or failure) of that in div1, and refresh the messages on the page in div2. This needs (for as far as my knowledge reaches) two AJAX actions from which I both need the responseText.
The problem
What happens when I execute my script is that the second action (refresh a part of the page) happens before the deletion is executed. The result of this is that when the deletion has been executed, the page is already updated, and the deleted message is still there.
The script
What I now have is:
[code=javascript]
function doAjax(url, element_id, img_url)
{
var ajaxObject = createAjaxObjec t();
ajaxObject.open ('GET', url, true);
ajaxObject.onre adystatechange = function()
{
if(ajaxObject.r eadyState==4 && ajaxObject.stat us==200)
{
document.getEle mentById(elemen t_id).innerHTML = ajaxObject.resp onseText;
delete ajaxObject;
}
else
{
if(img_url)
document.getEle mentById(elemen t_id).innerHTML = '<img src="' + img_url + '" alt=""/>';
}
};
ajaxObject.send ();
}
[/code]
to execute the actions, and
[code=javascript]
function createAjaxObjec t()
{
var ajaxObject;
try
{
ajaxObject = new XMLHttpRequest( );
}
catch (e)
{
try
{
ajaxObject = new ActiveXObject(" Microsoft.XMLHT TP");
}
catch (e)
{
try
{
ajaxObject = new ActiveXObject(" Msxml2.XMLHTTP" );
}
catch (e)
{
return;
}
}
}
return ajaxObject;
}
[/code]
to create the AJAX object.
Comment