load.js 905 B

1234567891011121314151617181920212223242526272829303132333435
  1. function load_init() {
  2. $('#content').html('');
  3. $('#result').html('');
  4. var str = '<table border="1" width="100%">';
  5. str += '<tr><td colspan="2"><a href="#" id="post">post</a></td></tr>';
  6. str += '<tr><td>file:</td><td><input type="file" style="width:95%" id= "file"/></td></tr>';
  7. str += '</table>';
  8. $('#content').html(str);
  9. $('#post').click(function() {
  10. load_post();
  11. });
  12. }
  13. function load_post() {
  14. var formData = new FormData();
  15. $.each($('input[type=file]'), function(index, item) {
  16. formData.append('file', item.files[0]);
  17. });
  18. $.ajax({
  19. type : 'post',
  20. dataType : 'json',
  21. url : '../servlet/load',
  22. data : formData,
  23. contentType : false,
  24. cache : false,
  25. processData : false,
  26. xhrFields : {
  27. 'withCredentials' : true
  28. },
  29. crossDomain : true,
  30. success : function(json, status, req) {
  31. $('#result').html(JSON.stringify(json, null, 4));
  32. }
  33. });
  34. }