/Examples/Example13/Scripts/FileUpload/backload.demo.js

https://github.com/amitrksharma/Backload · JavaScript · 63 lines · 31 code · 7 blank · 25 comment · 0 complexity · 6faa943c344273b432b02d42fb88617f MD5 · raw file

  1. /*
  2. * jQuery File Upload Plugin JS Example 8.0.1
  3. * https://github.com/blueimp/jQuery-File-Upload
  4. *
  5. * Copyright 2010, Sebastian Tschan
  6. * https://blueimp.net
  7. *
  8. * Licensed under the MIT license:
  9. * http://www.opensource.org/licenses/MIT
  10. */
  11. /*jslint nomen: true, regexp: true */
  12. /*global $, window, navigator */
  13. $(function () {
  14. 'use strict';
  15. var url = '/Backload/UploadHandler';
  16. // Initialize the jQuery File Upload widget:
  17. $('#fileupload').fileupload({
  18. // Uncomment the following to send cross-domain cookies:
  19. //xhrFields: {withCredentials: true},
  20. url: url
  21. });
  22. // Enable iframe cross-domain access via redirect option:
  23. $('#fileupload').fileupload(
  24. 'option',
  25. 'redirect',
  26. window.location.href.replace(
  27. /\/[^\/]*$/,
  28. '/cors/result.html?%s'
  29. )
  30. );
  31. // Load existing files by an initial ajax request to the server after page loads up
  32. // This is done by a simple jQuery ajax call, not by the FIle Upload plugin.,
  33. // but the results are passed to the plugin with the help of the context parameter:
  34. // context: $('#fileupload')[0] and the $(this)... call in the done handler.
  35. // With ajax.context you can pass a JQuery object to the event handler and use "this".
  36. $('#fileupload').addClass('fileupload-processing');
  37. $.ajax({
  38. // Uncomment the following to send cross-domain cookies:
  39. //xhrFields: {withCredentials: true},
  40. url: url,
  41. dataType: 'json',
  42. context: $('#fileupload')[0]
  43. }).always(function () {
  44. $(this).removeClass('fileupload-processing');
  45. }).done(function (result) {
  46. $(this).fileupload('option', 'done')
  47. .call(this, null, { result: result });
  48. });
  49. });
  50. $("document").ready(function () {
  51. $('#fileupload')
  52. .bind('fileuploaddestroy', function (e, data) {
  53. // Event handler example. Do something if you need after file has been deleted on the server.
  54. // (Refer to the client side documentatio).
  55. });
  56. });