Unable to retrieve blob from SQL database in IE11

  • Context: JavaScript 
  • Thread starter Thread starter aheight
  • Start date Start date
  • Tags Tags
    Database Sql
Click For Summary

Discussion Overview

The discussion revolves around an issue with retrieving a blob from a SQL database using AJAX in Internet Explorer 11 (IE11). Participants explore the error "Invalid State Error" encountered when setting the response type to 'arraybuffer' and share potential workarounds and solutions.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant describes their implementation using AJAX to retrieve a blob from a MySQL database and reports an error in IE11 that does not occur in other browsers.
  • Another participant asserts that the issue is a known bug in IE11 that has not been fixed and suggests informing users of the incompatibility or using jQuery as an alternative.
  • A different participant mentions a workaround involving calling xhr.open() before setting responseType, noting that it should not be necessary but appears to resolve the issue.
  • A later reply confirms that the workaround worked for them, expressing gratitude for the assistance received.

Areas of Agreement / Disagreement

Participants generally agree that the issue is a bug in IE11, but there are multiple proposed workarounds, and the effectiveness of these solutions may vary among users.

Contextual Notes

Some participants reference external links for additional workarounds, indicating that the problem may depend on specific implementations or configurations.

aheight
Messages
318
Reaction score
108
Hi,

I am storing a blob in my database running wamp64/MySQL and I am using AJAX to retrieve it. The code works with Chrome, Edge, and FireFox but I obtain the error message "Invalid State Error" in the debugger for the line "xmlhttp.responseType='arraybuffer'" when I run it under IE11. I have used FileReader with responseType='blob' to read the blob but get a similar error so I just took out the FileReader. I've googled the error message but could not figure out how to solve the problem. I was wondering if someone could help me get my code to work with IE11. This is my Javascript:
JavaScript:
       xmlhttp = new XMLHttpRequest();
 
       xmlhttp.responseType='arraybuffer';
 
      xmlhttp.onreadystatechange = function()
      {
        if (this.readyState == 4 && this.status == 200)
        {
           theResponse=this.response;
           theBlobSize=theResponse.byteLength;
       
          // start type-casting the blob here
       }
     }
    xmlhttp.open("POST","getImagAlgebraicBlob.php",true);
    xmlhttp.send();

And the PHP code for getImagAlgebraicBlob.php uses PDO and is very simple:

PHP:
<?php

include 'algebraicFunctionBlobClass.php';

$blobObj = new algebraicFunctionBlob();

$a = $blobObj->selectImagBlob(132);

echo $a['imagWebGLData'];

?>
 
Technology news on Phys.org
It is a bug and it was not fixed for IE11 because it is not within that place's team control. There are no indications of them planning to fix it for that browser. Even on Edge they marked it as NOT REPRODUCIBLE despite it being the most basic example that could be provided.

You could tell the people visiting your site using those browsers that the site is incompatible due to a very old bug that was not fixed in them and suggest that they use another browser.

Or you could use jQuery. If you decide to use jQuery, you could try this:
JavaScript:
$.ajax({
  method: "POST",
  url: "getImagAlgebraicBlob.php",
})
  .done(function(returnedResponse ) {
    //Convert 'returnedResponse' into an Uint8Array so that an ArrayBuffer can be used
    theResponse = new Uint8Array(returnedResponse);
    theBlobSize = theResponse.prototype.buffer.byteLength;
  });

Edit: code comment edited
 
Last edited:
  • Like
Likes   Reactions: harborsparrow and aheight
  • Like
Likes   Reactions: QuantumQuest, Psinter and aheight
Outstanding guys! Yes, I tried the work-around setting responseType after xhr.open() and it worked. Thanks a bunch guys for helping me with setting up all the pieces to get this software up and running!