Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8362785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:01:18+00:00 2026-06-09T12:01:18+00:00

I am trying to read a binary file MyFile.xxx that is at the same

  • 0

I am trying to read a binary file MyFile.xxx that is at the same domain as MyFile.html. Using JQuery I just try to display an alert with the number of characters in MyFile.xxx, and print the numeric representation of each one. However, I get different results depending on the browser:

Google Chrome: I correctly get an alert displaying 33, and the correct integers
Firefox: Alert displays “Undefined” and no integers are printed.
IE9: Alert displays “1” and no integers are printed.

Any ideas? Thanks

MyFile.html

<html>                                                                  
 <head>                                                                  
 <script type="text/javascript" src="jquery.js"></script>          
 <script type="text/javascript">                                         
    $.get('/MyFile.xxx', function(a){
    var l=a.length,x=[l];
    alert(l);
    for(i=0;i<l;i++){
      x[i]=a[i].charCodeAt(0);
      document.write(x[i]);
      document.write("<br>");
    }    
});                              
 </script>                                                               
 </head>                                                                 
 <body>                                                                  
 </body>                                                                 
 </html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T12:01:19+00:00Added an answer on June 9, 2026 at 12:01 pm

    Try this:

    $.ajax( "/MyFile.xxx", {
        dataType: "text",
        beforeSend: function( xhr ) {
            xhr.overrideMimeType( "text/plain; charset=x-user-defined");
        },
    
        success: function( data ) {
            var len = data.length,
                str = "";
    
            for( var i = 0; i < len; ++i ) {
                var byte = data.charCodeAt(i) & 0xFF;
                str += byte + " ";
    
            }
            document.body.innerHTML = str;
        }
    });
    

    Demo: http://jsfiddle.net/SXgfu/ (Shows the UTF-8 bytes for åöä)

    Note that IE9 does not support this. It does not support any other ways of getting raw bytes of the response either.

    If you are using PHP, you could use this work-around for IE:

    $.get("/base64encoder.php?file=MyFile.xxx", function(data) {
        data = decode64(data);
        var len = data.length,
            str = "";
        for (var i = 0; i < len; ++i) {
            var byte = data.charCodeAt(i) & 0xFF;
            str += byte + " ";
        }
        document.body.innerHTML = str;
    }, "text");
    

    Where base64encoder.php is something like:

    <?php
    echo base64_encode(file_get_contents( $_GET['file'] ));
    

    remember to sanitize the above, otherwise it’s a huge security vulnerability

    and decode64 (src http://ntt.cc/2008/01/19/base64-encoder-decoder-with-javascript.html):

    var keyStr = "ABCDEFGHIJKLMNOP" +
               "QRSTUVWXYZabcdef" +
               "ghijklmnopqrstuv" +
               "wxyz0123456789+/" +
               "=";
    
    function decode64(input) {
        var output = "";
        var chr1, chr2, chr3 = "";
        var enc1, enc2, enc3, enc4 = "";
        var i = 0;
        // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
        var base64test = /[^A-Za-z0-9\+\/\=]/g;
        if (base64test.exec(input)) {
            alert("There were invalid base64 characters in the input text.\n" + "Valid base64 characters are A-Z, a-z, 0-9, '+', '/',and '='\n" + "Expect errors in decoding.");
        }
        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
        do {
            enc1 = keyStr.indexOf(input.charAt(i++));
            enc2 = keyStr.indexOf(input.charAt(i++));
            enc3 = keyStr.indexOf(input.charAt(i++));
            enc4 = keyStr.indexOf(input.charAt(i++));
            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;
            output = output + String.fromCharCode(chr1);
            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }
            chr1 = chr2 = chr3 = "";
            enc1 = enc2 = enc3 = enc4 = "";
        } while (i < input.length);
        return output;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to read a binary file that consists of 2 byte floats, but
I am trying to read a binary file from a program that writes a
I am trying to read the number of line in a binary file using
I'm trying to display image data read in from a binary file (I have
I'm trying to read a binary file that is in the following format: number
Iam trying to read a binary file to memory and pass the starting address
I'm trying to read the binary data from a binary file with the code
I'm experiencing some problems while trying to read a binary file in C. This
I'm trying to read data from a binary file and put it into a
I'm trying to store some binary data obtained from read() in my buffer using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.