Guest User

Untitled

a guest
Feb 14th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. $('...').on('change', function () {
  2. var filearr = [];
  3. var myfile = document.getElementById('file');
  4. var files = this.files;
  5. var formData = new FormData();
  6.  
  7. for (var i = 0; i < files.length; i++) {
  8. //提交时,我们把filearr中的数据遍历一遍
  9. console.log(i, files[i]);
  10. formData.append('file', files[i]); //用append添加到formData中
  11. }
  12.  
  13. $.ajax({
  14. url: '',
  15. type: 'POST',
  16. data: formData,
  17. cache: false, //不设置缓存
  18. processData: false, // 不处理数据
  19. contentType: false, // 不设置内容类型
  20. success: function(res) {
  21. $('#head-img-base64').val(res);
  22. },
  23. error: function(e) {
  24. console.log(e);
  25. }
  26. });
  27. })
Add Comment
Please, Sign In to add comment