JavaScript Unable to retrieve blob from SQL database in IE11

  • Thread starter Thread starter aheight
  • Start date Start date
  • Tags Tags
    Database Sql
Click For Summary
The discussion revolves around an issue with retrieving a blob from a MySQL database using AJAX in Internet Explorer 11, which throws an "Invalid State Error" when setting `xmlhttp.responseType` to 'arraybuffer'. The code works in modern browsers like Chrome, Edge, and Firefox, but fails in IE11 due to a known bug that remains unresolved. Suggested solutions include informing users about the incompatibility of the site with IE11 or switching to jQuery for AJAX calls. A workaround was identified where setting `responseType` after calling `xhr.open()` resolves the error. This approach has been confirmed to work, allowing the code to function correctly in IE11. Additional resources were shared for further assistance.
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 harborsparrow and aheight
  • Like
Likes 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!
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...