fork download
  1. func homeHandler(w http.ResponseWriter, req *http.Request) {
  2. w.Header().Set("Content-Type", "text/html")
  3. var text = `
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <script src='http://a...content-available-to-author-only...s.com/ajax/libs/jquery/1.11.2/jquery.min.js'></script>
  8. <script type="text/javascript">
  9. var fileName = '';
  10. function fileSelected() {
  11. try {
  12. var file = document.getElementById('TheFile').files[0];
  13. if (file) {
  14. fileName = file.name;
  15. }
  16. } catch(err) {
  17. //nothing
  18. }
  19. uploadFile();
  20. }
  21.  
  22. function uploadFile() {
  23. try {
  24. var fd = new FormData();
  25. fd.append("TheFile", document.getElementById('TheFile').files[0]);
  26. var xhr = new XMLHttpRequest();
  27. xhr.upload.addEventListener("progress", uploadProgress, false);
  28. xhr.addEventListener("load", uploadComplete, false);
  29. xhr.addEventListener("error", uploadFailed, false);
  30. xhr.addEventListener("abort", uploadCanceled, false);
  31. xhr.open("POST", "/upload");
  32. xhr.onreadystatechange = function() {
  33. if (xhr.readyState == 4 && xhr.status == 200) {
  34. mycallback(xhr.responseText); // Another callback here
  35. }
  36. };
  37. xhr.send(fd);
  38. } catch(err) {
  39. document.getElementById("fileForm").submit();
  40. }
  41. }
  42.  
  43. function mycallback(data) {
  44. //alert(data);
  45. $('#result').html(data);
  46. }
  47.  
  48. function uploadProgress(event) {
  49. //if (evt.lengthComputable) {
  50. // var percentComplete = Math.round(event.loaded * 100 / event.total);
  51. // document.getElementById('progressNumber').innerHTML = percentComplete.toString() + '%';
  52. //}
  53. }
  54.  
  55. function uploadComplete(event) {
  56. //document.getElementById('progressNumber').innerHTML = 'Upload Complete for ' + fileName;
  57. }
  58.  
  59. function uploadFailed(event) {
  60. //document.getElementById('progressNumber').innerHTML = 'Error';
  61. }
  62.  
  63. function uploadCanceled(event) {
  64. //document.getElementById('progressNumber').innerHTML = 'Upload canceled';
  65. }
  66. </script>
  67.  
  68. </head>
  69. <body>
  70. <input type="file" name="TheFile" id="TheFile" onchange="fileSelected()" style="width: 600px; height: 40px; background: white;"><BR>
  71. <div id="progressNumber"></div>
  72. <div id='result'></div>
  73. </body>
  74. </html>
  75. `
  76. w.Write([]byte(text))
  77. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty