No Description

get-binary-files-ajax.html 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. ---
  2. title: "Get a file with an ajax call"
  3. layout: default
  4. section: example
  5. ---
  6. <h3>With JSZipUtils</h3>
  7. Note: JSZipUtils is a library available <a href="https://github.com/stuk/jszip-utils">here</a>.
  8. <ul class="nav nav-tabs" role="tablist">
  9. <li role="presentation" class="active">
  10. <a href="#jszip-utils-result" aria-controls="jszip-utils-result" role="tab" data-toggle="tab">
  11. result
  12. </a>
  13. </li>
  14. <li role="presentation">
  15. <a href="#jszip-utils-js" aria-controls="jszip-utils-js" role="tab" data-toggle="tab">
  16. js code
  17. </a>
  18. </li>
  19. <li role="presentation">
  20. <a href="#jszip-utils-html" aria-controls="jszip-utils-html" role="tab" data-toggle="tab">
  21. html code
  22. </a>
  23. </li>
  24. </ul>
  25. <div class="tab-content">
  26. <div role="tabpanel" class="tab-pane active" id="jszip-utils-result">
  27. <div class="show-example">
  28. {% include_relative get-binary-files-ajax.inc/jszip_utils.html %}
  29. </div>
  30. </div>
  31. <div role="tabpanel" class="tab-pane" id="jszip-utils-js">
  32. {% highlight js %}
  33. {% include_relative get-binary-files-ajax.inc/jszip_utils.js %}
  34. {% endhighlight %}
  35. </div>
  36. <div role="tabpanel" class="tab-pane" id="jszip-utils-html">
  37. {% highlight html %}
  38. {% include_relative get-binary-files-ajax.inc/jszip_utils.html %}
  39. {% endhighlight %}
  40. </div>
  41. </div>
  42. <h3>With the Fetch API</h3>
  43. Note: the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API">
  44. Fetch API</a> is a new javascript API which may not be available everywhere.
  45. <ul class="nav nav-tabs" role="tablist">
  46. <li role="presentation" class="active">
  47. <a href="#fetch-api-result" aria-controls="fetch-api-result" role="tab" data-toggle="tab">
  48. js code
  49. </a>
  50. </li>
  51. <li role="presentation">
  52. <a href="#fetch-api-js" aria-controls="fetch-api-js" role="tab" data-toggle="tab">
  53. js code
  54. </a>
  55. </li>
  56. <li role="presentation">
  57. <a href="#fetch-api-html" aria-controls="fetch-api-html" role="tab" data-toggle="tab">
  58. html code
  59. </a>
  60. </li>
  61. </ul>
  62. <div class="tab-content">
  63. <div role="tabpanel" class="tab-pane active" id="fetch-api-result">
  64. <div class="show-example">
  65. {% include_relative get-binary-files-ajax.inc/fetch_api.html %}
  66. </div>
  67. </div>
  68. <div role="tabpanel" class="tab-pane" id="fetch-api-js">
  69. {% highlight js %}
  70. {% include_relative get-binary-files-ajax.inc/fetch_api.js %}
  71. {% endhighlight %}
  72. </div>
  73. <div role="tabpanel" class="tab-pane" id="fetch-api-html">
  74. {% highlight html %}
  75. {% include_relative get-binary-files-ajax.inc/fetch_api.html %}
  76. {% endhighlight %}
  77. </div>
  78. </div>
  79. <script type="text/javascript">
  80. (function () {
  81. //=========================
  82. // JSZipUtils
  83. //=========================
  84. (function () {
  85. {% include_relative get-binary-files-ajax.inc/jszip_utils.js %}
  86. })();
  87. //=========================
  88. // Fetch API
  89. //=========================
  90. (function () {
  91. var elt = document.getElementById('fetch');
  92. if(typeof window.fetch === "function") {
  93. {% include_relative get-binary-files-ajax.inc/fetch_api.js %}
  94. } else {
  95. $("#fetch").append($("<p>", {
  96. "class": "alert alert-danger",
  97. text: "This browser doesn't support the Fetch API."
  98. }));
  99. }
  100. })();
  101. })();
  102. </script>