Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ajax js issue in FF 1

Status
Not open for further replies.

Bastien

Programmer
May 29, 2000
1,683
CA
I hav an intersting issue with the below JS code, works in IE and Chrome but not in FF. The ajax call brings back the results which I can see with Firebug. The idea is that the function gets passed the DIV parameter and checks to see what that is:
object (usually a div);
another function (to pass the results to) or
a string which gets returned to the calling function

So the only thing that doesn't seem to be executing is the div branch where the results are innerHTML'd into the div that I pass in. Am I doing something wrong in the test for the DIV with regard to FF?

Code:
function Ajax(url, data, div, Asynch)
{
// url   string   url of the page to activate
// data  string   data to be passed to the server
// div   object   div name as object,  function name to be have the result passed to when returned,   empty string to return the response to the calling function
  var objAjax = getAjaxObject();

    if (objAjax != null){

	    objAjax.onreadystatechange = function(){ 
        if (objAjax.readyState == 4) {
		           
	       if (objAjax.status == 200) {
	           strResponse = objAjax.responseText;

	           switch (typeof(div))
                   {
                     case "object":
                       if (div.style.display == 'none'){ div.style.display = 'inline'; }
                        div.innerHTML = strResponse;
                       break;

                     case "function":
                      div(strResponse);
                      break;

                     case "string":
                      return strResponse;
                      break;
                  }//end switch
                  objAjax = null;
            
              }else{
                alert("[" + objAjax.status + "]  Error: " + objAjax.reponseText);
              }//end if(objAjax.status == 200)

          }//end if(objAjax.readyState == 4) 	     
       }//end anon function
	
	    sendRequest(objAjax, "POST", url, Asynch, data);

  }//(objAjax != null)
}//end function

Bastien

I wish my computer would do what I want it to do,
instead of what I tell it to do...
 
Surely the most obvious thing to do is to alert typeof(div) in the section of code that checks its type, and see what Fx shows?

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Worked it out, FF doesn't like asynch set to true for the onreadystatechange status. I set it to false and now it works

Bastien

I wish my computer would do what I want it to do,
instead of what I tell it to do...
 
It stated in the FF docs that it doesn't like the sync value to be true. I found it strange myself, but it's now works.

Bastien

I wish my computer would do what I want it to do,
instead of what I tell it to do...
 
Hi

Thanks, I saw that.

Searching the page history you may find various notes like this :
MDC said:
Note: Versions of Firefox prior to version 3 always call the [tt]onreadystatechange[/tt] handler even if the request is synchronous.
Then the note disappears.

( Note : I hate collaborative content. <- And this note will never disappear. )

So I am not absolutely dumb, just my knowledge is relatively outdated.

Thank you for the information, Bastien. [medal] I learned something again.


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top