I use XMLHttpRequest to retrieve an image from a server (executed locally from a third-party applet server)
The following is a simplified version of the code .
The image is returned as JPEG, and the returned header shows "content-type = image / jpg". I can view information through Firebug for Firefox.
However, I have a terrible time to display the actual image on the web page because it is image data returned from the NOT uri server to the image location.
What is the correct way to display this image from the returned data? Should I use the <span> tag or the <img> tag or the <magical-show-image-from-data> ?
function getXML(url, postData, requestStateChangeHandler){ if(window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {//Code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = requestStateChangeHandler; xmlhttp.open("POST", url, true); xmlhttp.setRequestHeader('Content-Type', 'text/xml'); xmlhttp.setRequestHeader('Cache-Control', 'no-cache'); xmlhttp.send(postData); } function requestStateChangeHandler(){ if (xmlhttp.readyState == 4) { if(xmlhttp.status == 200) { document.getElementById('results').innerHTML = xmlhttp.responseText; } else dump("Error loading page\n"); } }
javascript dom html xml image
Toymakerii
source share