473,372 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

Binary Get w/ XHTMLHttprequest

Hi all...
I need to load an image, access it's content and render it.

So, tried:

<script type="text/javascript">

xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", "http://127.0.0.1/image.jpg", false);
xmlHttp.send(null);
imgbin = xmlHttp.responseText;

alert(imgbin.charAt(10)); //just for testing the access
//returns an empty box
</script>

<img src="javascript:imgbin">
Since the javascript code works for html files, i think the problem is
the binary content.

The <img src...> failed too.

Any Hints???

Jul 23 '05 #1
17 5604


jo*********@yahoo.com wrote:

I need to load an image, access it's content and render it.
How about
var img = document.createElement('img');
img.src = 'whatever.gif';
img.alt = 'whatever';
document.body.appendChild(img);
if you need to do it dynamically.
So, tried:

<script type="text/javascript">

xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", "http://127.0.0.1/image.jpg", false);
xmlHttp.send(null);
imgbin = xmlHttp.responseText;


It is called responseText for a reason.
I think MSXML also has a responseBody property but I don't think
JavaScript can do much with that but passing it on to another method
that can take such an array of bytes as JavaScript itself doesn't know
bytes.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
<jo*********@yahoo.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hi all...
I need to load an image, access it's content and render it.

So, tried:

<script type="text/javascript">

xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", "http://127.0.0.1/image.jpg", false);
xmlHttp.send(null);
imgbin = xmlHttp.responseText;

alert(imgbin.charAt(10)); //just for testing the access
//returns an empty box
</script>

<img src="javascript:imgbin">
Since the javascript code works for html files, i think the problem is
the binary content.

The <img src...> failed too.

Any Hints???


Why not just:

<img src="http://127.0.0.1/image.jpg">
Jul 23 '05 #3
Because i need to access it's content first.

Jul 23 '05 #4
Some texts on internet says it is possible but don't show an example,
or a code like mine.

Jul 23 '05 #5


jo*********@yahoo.com wrote:
Some texts on internet says it is possible


I don't think that the JavaScript string type can deal with binary image
data, if I try the following with Mozilla (where kiboInside.gif is a GIF
image Mozilla can render without problems when directly referenced in
the source attribute of an <img> element) Mozilla fails to render the
dynamically created image correctly, it has the right dimensions but
nothing more:

var httpRequest;
if (typeof XMLHttpRequest != 'undefined') {
httpRequest = new XMLHttpRequest();
httpRequest.open('GET', 'kiboInside.gif', true);
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState == 4) {
var status = httpRequest.status + ' ' + httpRequest.statusText +
'\r\n' +
'length: ' + httpRequest.responseText.length + '\r\n' +
httpRequest.responseText;
alert(status);
window.imgSource = httpRequest.responseText;
var img = document.createElement('img');
img.src = 'javascript:imgSource';
document.body.appendChild(img);
}
};
httpRequest.send(null);
}

And the length of the string responseText displayed is not the number of
bytes that Windows shows me for that image file.

And IE/Win for instance doesn't support
<img src="javascript:...">
at all, otherwise the pnglets from
<http://www.elf.org/pnglets/>
would work with IE.


--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #6
<jo*********@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Because i need to access it's content first.


Why? What do you want to do with binary data?
Jul 23 '05 #7
I need to check if the image sent was the one that i want.

//algorithm

if(image.data == "data i want"){
show("Yes it is the rigth image");
}
else{
show("Wrong image");
}

Jul 23 '05 #8
<jo*********@yahoo.com> wrote in message
news:11********************@z14g2000cwz.googlegrou ps.com...
I need to check if the image sent was the one that i want.

//algorithm

if(image.data == "data i want"){
show("Yes it is the rigth image");
}
else{
show("Wrong image");
}


I still don't understand -- but I don't have it as I'm just curious.

1) Wouldn't "image.data" contain binary data?

2) Wouldn't your script have to contain binary data as well for
comparison?
Jul 23 '05 #9
1) Yes.

2) Supose we have files on Gif, jpg and bmp. How could i check this
files without opening the binary?
I would have to convert it to RGB for example and then check
'imgae[ i ] [ j ]'.
It's a lot of work and would collapses my system.

Jul 23 '05 #10
Martin Honnen wrote:
<snip>
And IE/Win for instance doesn't support
<img src="javascript:...">

<snip>

That isn't quite true (though for all practical purposes it is). IE can
do javascript: SRCs on images, but only when the image format is XBM.
XBM being an image format where the data is defined as text, so a long
way form being an efficient form as it takes 5+ characters to define a
byte. It is also a two color format (black and transparent):

var trash = "#define trash_width 16\n#"+
"define trash_height 16\n"+
"static char trash_bits[] = {"+
"0x00,0x01,0xe0,0x0f,"+
"0x10,0x10,0xf8,0x3f,"+
"0x10,0x10,0x50,0x15,"+
"0x50,0x15,0x50,0x15,"+
"0x50,0x15,0x50,0x15,"+
"0x50,0x15,0x50,0x15,"+
"0x50,0x15,0x10,0x10,"+
"0xe0,0x0f,0x00,0x00"+
"};";
....
<img src="javascript:trash" width="16" height="16" alt="Trash Can">

Mozilla is much happier with this general idea and will show
(apparently) any recognised graphic format. E.G.:-

var crossGif =
"\u0047\u0049\u0046\u0038\u0039\u0061\u002b\u0000" +
"\u002b\u0000\ufff0\u0000\u0000\ufffd\u0000\u0000" +
"\uffff\uffff\uffff\u0021\ufff9\u0004\u0001\u0000" +
"\u0000\u0001\u0000\u002c\u0000\u0000\u0000\u0000" +
"\u002b\u0000\u002b\u0000\u0040\u0002\u0078\uff8c" +
"\uff8f\uff99\uffa0\uffed\u000f\u000d\uff8b\ufff4" +
"\u004d\u0075\u0057\uff8d\u0019\ufff5\ufff3\u006d" +
"\u0055\u0028\uff96\uff9e\uff89\u0036\u0064\u006a" +
"\u0069\uffa7\u0008\uffc4\ufff2\u004c\uffd7\ufff6" +
"\u006d\u006f\uffdd\uffce\uff96\u006b\u004f\ufff9" +
"\u0001\u0021\uffc2\uffe1\uffa2\u0066\u0054\u0029" +
"\u0031\uffc6\uff95\u0013\ufff8\u0074\u0014\uff83" +
"\u004b\u0057\uffd2\uff83\uffbc\u0052\uffb5\u003a" +
"\u006e\uffd7\uffbb\u0005\u0013\uffc5\u001c\ufff2" +
"\uffd8\u002c\u0045\uff83\u002e\uffec\uffa9\uffe9" +
"\u0003\uffbf\uff92\uffe6\uffc3\u0068\u0035\u0065" +
"\u0067\ufff6\ufff2\u0056\u007c\u002b\u000d\u0005" +
"\uffa8\uffd7\u0034\u0008\u0002\u0016\u0063\u0028" +
"\uffe1\u0056\uffa7\u0076\uffd7\u0028\ufff1\uffd8" +
"\u0017\uffb9\uffa8\u0045\uffa9\u0050\u0000\u0000" +
"\u003b";
....
<img src="javascript:crossGif" width="43" height="43"
alt="Cross Hairs (red)">

However, it is interesting to observe that the byte data from the
graphic is in the lower byte of the 16 bit Unicode character escapes
(some of which need to be padded, e.g. \uffa8, in order to keep that low
byte negative). I suspect that taking the responseText of an XML HTTP
request (nominally UTF-8) and making a javascript string out of it will
garble any data that was originally binary beyond being useful, even in
Mozilla.

Opera doesn't seem to be interested in javascript: SRCs at all, and is
unlikely to be alone in that.

Richard.


Jul 23 '05 #11


Richard Cornford wrote:
Martin Honnen wrote:
And IE/Win for instance doesn't support
<img src="javascript:...">

That isn't quite true (though for all practical purposes it is). IE can
do javascript: SRCs on images, but only when the image format is XBM.


Right, I certainly forgot about XBM images when I wrote that. However at
least IE 6 on Windows XP SP 2 doesn't display the XBM for me:
<http://home.arcor.de/martin.honnen/javascript/200501/test2005010801.html>
I am not sure what earlier IE versions did, might run some tests later.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #12


Martin Honnen wrote:
Richard Cornford wrote:
IE can
do javascript: SRCs on images, but only when the image format is XBM.


Right, I certainly forgot about XBM images when I wrote that. However at
least IE 6 on Windows XP SP 2 doesn't display the XBM for me:
<http://home.arcor.de/martin.honnen/javascript/200501/test2005010801.html>
I am not sure what earlier IE versions did, might run some tests later.


It seems that IE 5, 5.5 can display the XBM provided in a JavaScript
string. Could anyone confirm that IE 6 on Windows XP SP 2 doesn't
display the image?
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #13
On Sat, 08 Jan 2005 15:22:33 +0100, Martin Honnen <ma*******@yahoo.de>
wrote:
It seems that IE 5, 5.5 can display the XBM provided in a JavaScript
string. Could anyone confirm that IE 6 on Windows XP SP 2 doesn't
display the image?


doesn't for me on that combo

Jim.
Jul 23 '05 #14
Jim Ley wrote:
Martin Honnen wrote:
It seems that IE 5, 5.5 can display the XBM provided in
a JavaScript string. Could anyone confirm that IE 6 on
Windows XP SP 2 doesn't display the image?


doesn't for me on that combo


It must be an XP SP 2 thing rather than IE 6 (which displays the XBM
fine for me on other OSs).

Still, I never thought there was much value in the limited and patchy
support for javascript: image SRCs so losing it on modern IE
installations is no great loss.

Richard.
Jul 23 '05 #15
IE 6.0.2800.1106.xpsp2.040919-1003 shows the trashcan
"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:41**********************@newsread4.arcor-online.net...


Martin Honnen wrote:
Richard Cornford wrote:
IE can
do javascript: SRCs on images, but only when the image format is XBM.


Right, I certainly forgot about XBM images when I wrote that. However at
least IE 6 on Windows XP SP 2 doesn't display the XBM for me:
<http://home.arcor.de/martin.honnen/javascript/200501/test2005010801.html> I am not sure what earlier IE versions did, might run some tests later.


It seems that IE 5, 5.5 can display the XBM provided in a JavaScript
string. Could anyone confirm that IE 6 on Windows XP SP 2 doesn't
display the image?
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #16
On Sat, 08 Jan 2005 16:55:43 GMT, "Dag Sunde" <me@dagsunde.com> wrote:
It seems that IE 5, 5.5 can display the XBM provided in a JavaScript
string. Could anyone confirm that IE 6 on Windows XP SP 2 doesn't
display the image?
IE 6.0.2800.1106.xpsp2.040919-1003 shows the trashcan


IE 6.0.2900.2180.xpsp_sp2_rtm.040803-2158 is mine that doesn't...

Jim.
Jul 23 '05 #17
Jim Ley wrote:
On Sat, 08 Jan 2005 16:55:43 GMT, "Dag Sunde" <me@dagsunde.com> wrote:

It seems that IE 5, 5.5 can display the XBM provided in a JavaScript
string. Could anyone confirm that IE 6 on Windows XP SP 2 doesn't
display the image?


IE 6.0.2800.1106.xpsp2.040919-1003 shows the trashcan

IE 6.0.2900.2180.xpsp_sp2_rtm.040803-2158 is mine that doesn't...


That is the same one I have and no trash can.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: yaipa | last post by:
What would be the common sense way of finding a binary pattern in a ..bin file, say some 200 bytes, and replacing it with an updated pattern of the same length at the same offset? Also, the...
20
by: Christian Stigen Larsen | last post by:
A signed int reserves one bit to signify whether a number is positive or negative. In light of this, a colleague asked me whether there existed an int in C++ that was -0, a zero with the negative...
3
by: Tron Thomas | last post by:
What does binary mode for an ofstream object do anyway? Despite which mode the stream uses, operator << writes numeric value as their ASCII representation. I read on the Internet that it is...
103
by: Steven T. Hatton | last post by:
27.4.2.1.4 Type ios_base::openmode Says this about the std::ios::binary openmode flag: *binary*: perform input and output in binary mode (as opposed to text mode) And that is basically _all_ it...
2
by: Lisa Pearlson | last post by:
Hi, My php application (on Apache/Linux) needs to do the following: The PHP script receives a request from a client (binary), asking for certain records of data. My PHP script loops through...
9
by: Ching-Lung | last post by:
Hi all, I try to create a tool to check the delta (diff) of 2 binaries and create the delta binary. I use binary formatter (serialization) to create the delta binary. It works fine but the...
3
by: John R. Delaney | last post by:
I am running in debugging mode after a clean C++ compilation under .NET 2003. In a BIG loop (controlled many levels up in the call stack), I open a file with fopen using the "a" option. Then I write...
10
by: rory | last post by:
I can't seem to append a string to the end of a binary file. I'm using the following code: fstream outFile("test.exe", ios::in | ios::out | ios::binary | ios::ate | ios::app)...
16
by: Erwin Moller | last post by:
Why is a binary file executable? Is any binary file executable? Is only binary file executable? Are all executable files binary? What is the connection between the attribute of binary and that of...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.