Sunday 15 August 2010

javascript - Get img from DOM and upload it via ajax -


How can I get an image from the DOM and then upload it through AJAX? my_img_ele = document.getElementById ("my_img");

This is an AJAX call

  var xmlHttp = new XMLHttpRequest (); XmlHttp.open ("post", "site", true); Var formatta = new form data (); FormData.append (IMG_HERE); XmlHttp.send (formData);   

What I'm doing is just sending the URL and then looking at the image server. But I think it will be faster.

EDIT: Note that the user is not uploading a picture through a form. This is an IMG element.

Your data is clearly incorrect, it is a matter of fact that an image element is something other than a DOM node Not included, which contains the URL of the image, the image itself is downloaded by the browser, so on the client machine it is only available in the browser memory. And even if you somehow get the benefit of browser memory (cash), it is highly possible that it is slow to upload from the original source to the server side, based on the client connection. The solution is that you download the image based on the URL (IMGSRC) through AJAX, it rotates with the second ajax in the previous callback, but of course This means that the image is two times more than the average.

No comments:

Post a Comment