Ajax Load Picture

Source: Internet
Author: User
Tags date client
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);

Related Article

Cloud Intelligence Leading the Digital Future

Alibaba Cloud ACtivate Online Conference, Nov. 20th & 21st, 2019 (UTC+08)

Register Now >

11.11 Big Sale for Cloud

Get Unbeatable Offers with up to 90% Off,Oct.24-Nov.13 (UTC+8)

Get It Now >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.