Skip to content

Commit 26454a0

Browse files
author
Pablo Brasero Moreno
committed
Include example of object detection
1 parent b9adc37 commit 26454a0

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

public/index.html

+31-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,40 @@
55
<title>Ajax upload form</title>
66
</head>
77
<body>
8+
9+
<p id="support-notice">Your browser does not support Ajax uploads :-(<br/>The form will be submitted as normal.</p>
10+
811
<form action="/" method="post" enctype="multipart/form-data" id="form-id">
9-
<p><input id="file-id" type="file" name="our-file" /> <input type="button" value="Upload" id="upload-button-id" /></p>
12+
<p><input id="file-id" type="file" name="our-file" /> <input type="button" value="Upload" id="upload-button-id" disabled="disabled" /></p>
1013
<p><label>Some other field: <input name="other-field" type="text" id="other-field-id" /></label></p>
11-
<p><input type="submit" value="Save" /></p>
14+
<p><input type="submit" value="Submit" /></p>
1215
<script>
16+
function supportAjaxUploadWithProgress() {
17+
return supportFileAPI() && supportAjaxUploadProgressEvents() && supportFormData();
18+
19+
function supportFileAPI() {
20+
var fi = document.createElement('INPUT');
21+
fi.type = 'file';
22+
return 'files' in fi;
23+
};
24+
25+
function supportAjaxUploadProgressEvents() {
26+
var xhr = new XMLHttpRequest();
27+
return !! (xhr && ('upload' in xhr) && ('onprogress' in xhr.upload));
28+
};
29+
30+
function supportFormData() {
31+
return !! window.FormData;
32+
}
33+
}
34+
35+
if (supportAjaxUploadWithProgress()) {
36+
var notice = document.getElementById('support-notice');
37+
var uploadBtn = document.getElementById('upload-button-id');
38+
notice.innerHTML = "Your browser supports HTML uploads. Go try me! :-)";
39+
uploadBtn.removeAttribute('disabled');
40+
}
41+
1342
var form = document.getElementById('form-id');
1443
form.onsubmit = function() {
1544
var formData = new FormData(form);

0 commit comments

Comments
 (0)