There is a similar question for Jquery here: Asynchronously load images with jQuery
The accepted answer is quite clever and works well (for Jquery):
var img = $("<img />").attr('src', 'http://somedomain.com/image.jpg')
.load(function() {
if (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0) {
alert('broken image!');
} else {
$("#something").append(img);
}
});
My question is, what would be the canonical equivlent to this in Dojo (including the error handling)?
You can use "dojox.form.Uploader" to ajax upload image.
Dojo code:-
require(['dojox/form/Uploader'],function(Uploader)
{
var uploader = new Uploader(
{
uploadOnSelect:true, //Upload file on file select
url:'UploadFile.php', //Path of your server file
label:'', //Label of uploader
multiple:true //Select multiple file to upload
},'uploader');
uploader.startup();
});
HTML code:-
<div id="uploader"></div>
"dojox.form.Uploader" provide various properties, method and event which is help to upload file. I hope this will help you.