I am trying to find a solution to my problem, while I am trying to upload an image via AJAX.
I am using this code:
document.getElementById('file').addEventListener('change', function(e) {
var file = this.files[0];
console.log(file);
var xhr = new XMLHttpRequest();
(xhr.upload || xhr).addEventListener('progress', function(e) {
var done = e.position || e.loaded
var total = e.totalSize || e.total;
console.log('xhr progress: ' + Math.round(done/total*100) + '%');
});
xhr.addEventListener('load', function(e) {
console.log('xhr upload complete', e, this.responseText);
});
xhr.open('post', 'http://webpage.com/images', true);
var data = new FormData;
data.append('file', file);
xhr.send(data);
});
I found it here: jQuery Upload Progress and AJAX file upload
by @Rudie
I am getting 403 forbidden error and tried everything.. I am using opencart MVC archritecture to build my custom dashboard.. My website is hosted at goddady i) I do not have any .htaccess file on this folder ii) there is an option at cpanel of godaddy "hotlink protextion", I have also placed the URL in there! (http://webpage.com/images) iii) tried 777 as folder permission
but still same error.. I think this is the most appropriate code to my solution.. Any suggestions? what I am doing wrong?