Skip to content

Commit 6662b81

Browse files
author
Pablo Brasero Moreno
committed
Do not init Ajax code if not supported
1 parent 26454a0 commit 6662b81

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

public/index.html

+22-15
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,36 @@
3737
var uploadBtn = document.getElementById('upload-button-id');
3838
notice.innerHTML = "Your browser supports HTML uploads. Go try me! :-)";
3939
uploadBtn.removeAttribute('disabled');
40+
41+
initFullFormAjaxUpload();
42+
initFileOnlyAjaxUpload();
4043
}
4144

42-
var form = document.getElementById('form-id');
43-
form.onsubmit = function() {
44-
var formData = new FormData(form);
45-
var action = form.getAttribute('action');
45+
function initFullFormAjaxUpload() {
46+
var form = document.getElementById('form-id');
47+
form.onsubmit = function() {
48+
var formData = new FormData(form);
49+
var action = form.getAttribute('action');
4650

47-
sendXHRequest(formData, action);
51+
sendXHRequest(formData, action);
4852

49-
return false;
53+
return false;
54+
}
5055
}
5156

52-
var uploadBtn = document.getElementById('upload-button-id');
53-
uploadBtn.onclick = function (evt) {
54-
var formData = new FormData();
55-
var action = '/upload';
56-
var fileInput = document.getElementById('file-id');
57-
var file = fileInput.files[0];
58-
formData.append('our-file', file);
57+
function initFileOnlyAjaxUpload() {
58+
var uploadBtn = document.getElementById('upload-button-id');
59+
uploadBtn.onclick = function (evt) {
60+
var formData = new FormData();
61+
var action = '/upload';
62+
var fileInput = document.getElementById('file-id');
63+
var file = fileInput.files[0];
64+
formData.append('our-file', file);
5965

60-
sendXHRequest(formData, action);
66+
sendXHRequest(formData, action);
6167

62-
return false;
68+
return false;
69+
}
6370
}
6471

6572
function sendXHRequest(formData, uri) {

0 commit comments

Comments
 (0)