[Javascript] AJAX stopping

Michael Borchers list at tridemail.de
Mon Aug 21 05:17:29 CDT 2006


> it looks a bit confusing but here are some of my functions that use php 
> files. the files themselves worke fine.
>
> f.e. i can throw out the insertFolder or the refreshFolders function in 
> addFolder, each one alone works fine, but together none of them works.
>
> could it be a problem with 2 httpRequest calls or the 
> httpReques.send(null) ?!
>
>
> function addFolder()
> {
> var foldName = prompt('enter name:');
>
> if(foldName != null && foldName != '' && foldName != 'undefined')
> {
>  insertFolder(foldName);
> }
>
> refreshFolders();
> }
>
> function insertFolder(foldName)
> {
> httpRequest.open('get', 
> 'ajax.php?ajax_filename=insert_folder.php&folders_name=' + foldName, 
> true);
> httpRequest.onreadystatechange = function() { alertResponseText() };
> httpRequest.send(null);
> }
>
> function refreshFolders()
> {
> getFolders();
> }
>
> function getFolders()
> {
> httpRequest.open('get', ''ajax.php?ajax_filename=show_folders.php', true);
> httpRequest.onreadystatechange = function() { showFolders() };
> httpRequest.send(null);
> }
>
> function showFolders()
> {
> var ticketsFoldersDiv = document.getElementById('ticketsFoldersDiv');
>
> if(httpRequest.readyState == 4)
> {
>  ticketsFoldersDiv.innerHTML = httpRequest.responseText;
> }
> }
>
> function alertResponseText()
> {
> if(httpRequest.readyState == 4)
> {
>  if(httpRequest.status == 200)
>  {
>   alert(httpRequest.responseText);
>  }
> }
> }

found the "mistake": the ajax script of writing the folder is faster than 
the
refresh script. so the refresh script always gets the old folders and
the addFolder script breaks off afterwards.

i did a workaround, waiting for the readyState == 4 and then doing the
refresh. 




More information about the Javascript mailing list