ulvis.paste.net

Paste Search Dynamic
Recent pastes
test formdata upload
  1. <html>
  2. <head>
  3.     <title>test formdata upload</title>
  4. <script  src="https://code.jquery.com/jquery-2.1.4.min.js"
  5.   integrity="sha256-8WqyJLuWKRBVhxXIL1jBDD7SDxU936oZkCnxQbWwJVw="
  6.   crossorigin="anonymous"></script>
  7.     <script type="text/javascript">
  8.         var onProgress = function (e) {
  9.             if (e.lengthComputable) {
  10.                 document.getElementById("progressBar").style.width = Math.round(e.loaded * 100 / e.total) + 'px';
  11.             }
  12.         };
  13.         $(function () {
  14.             $('#uploadBtn').on('click', function () {
  15.                 var fdata = new FormData();
  16.                 fdata.append('file', $('#testFile')[0].files[0]);
  17.                 var xhr = new XMLHttpRequest();
  18.                 //xhr.onprogress = onProgress; //下载监听
  19.                 xhr.upload.onprogress = onProgress; //上传监听
  20.                 xhr.open("POST", "http://192.168.2.152:89/api/values", true);
  21.                 xhr.send(fdata);
  22.                 return false;
  23.             });
  24.         });
  25.     </script>
  26. </head>
  27. <body>
  28.     <div style="width:600px;margin:10px auto;background-color:#fff;">
  29.         <input type="file" id="testFile" name="testFile" multiple="multiple" />
  30.         <div id="progressBar" style="background-color:#ccf;height:6px;width:0px;border-radius:4px;border:0px;"></div>
  31.         <input id="uploadBtn" type="button" value="submit" />
  32.     </div>
  33. </body>
  34. </html>
  35.  
Parsed in 0.000 seconds