• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

XMLHttpRequest.onreadystatechange - FireFox vs IE

LEGEND ,
Jun 01, 2017 Jun 01, 2017

Copy link to clipboard

Copied

Hello, all,

I'm posting this question here because I don't have an account on any other forums, and I don't know where else to go.

I have a .cfm page that is using Javascript XHR to post a single word value to itself which will determine how something is going to be processed.

PSEUDOCODE:

<div class="thisNav" id="getStats">Get User Stats</div><div class="thisNav" id="pruStats">Prune Stats (6 mos)</div><div class="thisNav" id="expStats">Export User Stats</div>

<script>

     var thisNav = [].slice.call(document.getElementsByClassName('thisNav')).map(function(d){

          d.onclick = function(event){getThis(d.id);};

          });

     xhr = new XMLHttpRequest();

     function getThis(act){

          xhr.open("POST","filename.cfm",true);

          xhr.setRequestHeader("Content-Type","x-www-form-urlencoded");

          xhr.onreadystatechange = function(){

               if(xhr.readyState*1 === 1){anotherDiv.innerHTML = " OPENING";}

               elseif(xhr.readyState*1 === 3){anotherDiv.innerHTML = " DISPLAYING";}

               elseif(xhr.readyState*1 === 4 && xhr.status === 200){anotherDiv.innerHTML = xhr.responseText;}

               }

          xhr.send("act=" + act);

          }

</script>

Now, in Internet Explorer 11, this works well (I know, I can't believe it, either.)

However, in FireFox 52, this will only display the last stage (xhr.responseText) on the first click (will not see readyState 1 or 3).  Subsequent clicks (if I don't refresh the page) will work as expected, but the initial click will not.

What is the difference between FF and IE that could cause this??  Is there some kind of fix or workaround??

V/r,

^_^

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 01, 2017 Jun 01, 2017

Copy link to clipboard

Copied

I should add:  I've placed an alert(xhr.status) at the very beginning of the onreadystatechange.

IE11 is displaying all of the alerts at the precise times.

On the FIRST click, FF52 is only alerting status 4 and displaying the returned content.  So, for some reason, FF isn't seeing or reporting the first two status reports (1 and 3) and is apparently only seeing the last (status 4). Subsequent clicks without reloading/refreshing the page work as it does in IE11.

Is this due to some kind of setting within FF options???  Or in about:config???

V/r,

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 03, 2017 Jun 03, 2017

Copy link to clipboard

Copied

Does it help to do something like this?

if(xhr.readyState == 1){anotherDiv.innerHTML = " OPENING";} 

                   else if(xhr.readyState == 3){anotherDiv.innerHTML = " DISPLAYING";} 

                   else if(xhr.readyState == 4 && xhr.status == 200){anotherDiv.innerHTML = xhr.responseText;}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 05, 2017 Jun 05, 2017

Copy link to clipboard

Copied

LATEST

Sorry.. since my dev environment is isolated from the internet, I had to manually type all that code, and neglected to place a space between else and if.  It is as you have suggested.

V/r,

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation