Last active
October 22, 2018 08:15
-
-
Save AlexDemian/b493f9596be431438be2018ebb6eb4d3 to your computer and use it in GitHub Desktop.
Revisions
-
AlexDemian revised this gist
Oct 22, 2018 . 1 changed file with 11 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ <script> function readFile(file) { var http = new XMLHttpRequest(); http.open('get', file); http.onreadystatechange = function () { text = http.responseText; console.log(text); }; http.send(); }; </script> -
AlexDemian revised this gist
Oct 17, 2018 . 1 changed file with 20 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ <script> function send_post() { request = $.ajax({ url: "/url/", type: "post", data: 'forn_name='+JSON.stringify({'key':'value'}) }); request.done(function (response, textStatus, jqXHR){ console.log("Succesful!"); }); request.fail(function (jqXHR, textStatus, errorThrown){ console.error( "The following error occurred: "+ textStatus, errorThrown ); }); } </script> -
AlexDemian created this gist
Jul 13, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>Title</title> </head> <body> <input type="file" name="afile" id="afile" accept="img/*"/> <script> document.querySelector('#afile').addEventListener('change', function(e) { var file = this.files[0]; var fd = new FormData(); fd.append("binary_data", file); fd.append("fname", document.querySelector('#afile').value) var xhr = new XMLHttpRequest(); xhr.open('POST', '../path/to_cgi_script.py', true); xhr.upload.onprogress = function(e) { if (e.lengthComputable) { var percentComplete = (e.loaded / e.total) * 100; console.log(percentComplete + '% uploaded'); } }; xhr.onload = function() { alert(this.response); if (this.status == 200) { var resp = JSON.parse(this.response); console.log('Server got:', resp); } }; xhr.send(fd); }, false); </script> </body> </html>