ajax| loading
See a post in the jar < How to display binary data with JavaScript picture > see their reply, not the key, the main meaning of the landlord is backstage into the binarywrite () output a picture, Ajax received how to show it out. The colorful, The wind and the clouds. In fact, the landlord's meaning is to require the picture data received has not been completed before the "picture loading ..." effect to the user, once the data is completed receive immediately display.
We know that binary image data stored in a database is first read through the background, input to the client. In asp.net we use Response.BinaryWrite () to generate pictures to the browser, the client directly OK." If so, why do you use Ajax Ah, you say ... straight call not on the line. We also know that using JavaScript to load binary graphics data is cumbersome and is by no means a good idea.
Here are my ideas to achieve:
First of all: the background input picture is affirmative. What we need to solve is how do we know that the data received is complete? After the data is still binary data, how can we output to the browser? Oh. In fact very simple use cache, the same URL request will first call cache, receive XMLHTTP object return is received completed xhr.status=200, this time the picture has been downloaded to the cache directly The picture is displayed directly, because the same URL so the browser directly call the cache image data, remember Oh, the URL here to keep the same as Xhr.open () in the same URL. Here's a code reference.
function LoadImage (elementid,id)
{
ID of ElementID
Picture ID requested by ID
var url= "getimage.aspx?id=" +id+ "&stamptime=" +new Date (). GetTime (); Here you can refresh the picture with the new Date (). GetTime ()
var xhrobject = Getxhrobject ();
Xhrobject.onreadystatechange=function event ()
{
if (xhrobject.readystate==4)
{
if (xhrobject.status==200)
{
document.getElementById (ElementID). Src=url;
}
}
}
Xhrobject.open ("get", url);
Xhrobject.send (NULL);
}