{"id":1849,"date":"2016-04-15T23:51:43","date_gmt":"2016-04-15T14:51:43","guid":{"rendered":"https:\/\/ecpplus.net\/weblog\/?p=1849"},"modified":"2020-06-06T19:31:43","modified_gmt":"2020-06-06T10:31:43","slug":"ajax%e3%81%a7%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%83%80%e3%82%a6%e3%83%b3%e3%83%ad%e3%83%bc%e3%83%89","status":"publish","type":"post","link":"https:\/\/ecpplus.net\/weblog\/ajax%e3%81%a7%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%83%80%e3%82%a6%e3%83%b3%e3%83%ad%e3%83%bc%e3%83%89\/","title":{"rendered":"AJAX\u3067\u30d5\u30a1\u30a4\u30eb\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9"},"content":{"rendered":"<p>\u30d0\u30a4\u30ca\u30ea\u3067\u3082\u30c6\u30ad\u30b9\u30c8\u3067\u3082\u3001AJAX \u3067\u30ea\u30af\u30a8\u30b9\u30c8\u3057\u305f\u3089 JavaScript \u3067\u53d7\u3051\u308b\u3053\u3068\u306b\u306a\u308b\u306e\u3067\u3001\u30d6\u30e9\u30a6\u30b6\u306b\u30d5\u30a1\u30a4\u30eb\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3055\u305b\u308b\u3088\u3046\u306b\u51e6\u7406\u3092\u4f5c\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002<\/p>\n<blockquote><p>\n  Blob \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u30d5\u30a1\u30a4\u30eb\u306b\u4f3c\u305f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u3001immutable \u306a\u751f\u30c7\u30fc\u30bf\u3067\u3059\u3002\u30c7\u30fc\u30bf\u3092\u8868\u3059 blob \u306f\u5fc5\u305a\u3057\u3082 JavaScript \u30cd\u30a4\u30c6\u30a3\u30d6\u306a\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002File \u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u306f Blob \u3092\u57fa\u790e\u306b\u3057\u3066\u304a\u308a\u3001\u305d\u306e\u6a5f\u80fd\u3092\u7d99\u627f\u3059\u308b\u4e00\u65b9\u3067\u3001\u30e6\u30fc\u30b6\u306e\u30b7\u30b9\u30c6\u30e0\u4e0a\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u30b5\u30dd\u30fc\u30c8\u3059\u308b\u305f\u3081\u306e\u6a5f\u80fd\u3092\u62e1\u5f35\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>  <cite>https:\/\/developer.mozilla.org\/ja\/docs\/Web\/API\/Blob<\/cite>\n<\/p><\/blockquote>\n<p>\u3068\u306e\u3053\u3068\u3067\u3059\u3002\u30ec\u30b9\u30dd\u30f3\u30b9\u304b\u3089 Blob \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u3063\u3066\u3001createObjectURL \u3059\u308c\u3070\u3001\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u53ef\u80fd\u306aURL\u3092\u751f\u6210\u3059\u308b\u4e8b\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u3088\u304f\u3042\u308a\u304c\u3061\u306a\u3001CSV\u30c7\u30fc\u30bf\u3092\u7ba1\u7406\u753b\u9762\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3055\u305b\u305f\u3044\u3001\u307f\u305f\u3044\u306a\u30d1\u30bf\u30fc\u30f3\u3092 jQuery + ES6 \u3067\u66f8\u3044\u305f\u5834\u5408\u306e\u4f8b\u3002<\/p>\n<p>IE\u306e\u5834\u5408\u3001IE10\u4ee5\u4e0a\u3067\u3042\u308c\u3070 <code>msSaveBlob<\/code> \u3068\u3044\u3046\u3001Blob \u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u3068\u3044\u3046\u6a5f\u80fd\u3092\u4f7f\u3046\u3053\u3068\u304c\u51fa\u6765\u308b\u3002\u305d\u308c\u4ee5\u5916\u306e\u30d6\u30e9\u30a6\u30b6\u306f\u3001<code>createObjectURL<\/code> \u3092\u4f7f\u3063\u3066 URL \u3092\u751f\u6210\u3057\u305f\u3089\u3001a \u30bf\u30b0\u306e href \u306b\u30bb\u30c3\u30c8\u3057\u3066\u305d\u308c\u306b\u30af\u30ea\u30c3\u30af\u30a4\u30d9\u30f3\u30c8\u3092\u767a\u706b\u3055\u305b\u308b\u3068\u3044\u3046\u65b9\u6cd5\u3067\u5b9f\u73fe\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-js line-numbers\">$.ajax({\n  url: 'https:\/\/example.com\/api\/admin\/users.csv',\n  type: 'GET',\n}).done((data, status, jqXHR) =&gt; {\n  let downloadData = new Blob([data], {type: 'text\/csv'});\n  let filename = 'users.csv'\n\n  if (window.navigator.msSaveBlob) {\n    window.navigator.msSaveBlob(downloadData, filename); \/\/ IE\u7528\n  } else {\n    let downloadUrl  = (window.URL || window.webkitURL).createObjectURL(downloadData);\n    let link = document.createElement('a');\n    link.href = downloadUrl;\n    link.download = filename;\n    link.click();\n    (window.URL || window.webkitURL).revokeObjectURL(downloadUrl);\n  }\n}).fail((data, status, jqXHR) =&gt; {\n  alert('OMG!');\n});      \n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u30d0\u30a4\u30ca\u30ea\u3067\u3082\u30c6\u30ad\u30b9\u30c8\u3067\u3082\u3001AJAX \u3067\u30ea\u30af\u30a8\u30b9\u30c8\u3057\u305f\u3089 JavaScript \u3067\u53d7\u3051\u308b\u3053\u3068\u306b\u306a\u308b\u306e\u3067\u3001\u30d6\u30e9\u30a6\u30b6\u306b\u30d5\u30a1\u30a4\u30eb\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3055\u305b\u308b\u3088\u3046\u306b\u51e6\u7406\u3092\u4f5c\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002 Blob \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u30d5\u30a1\u30a4\u30eb\u306b\u4f3c\u305f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":2304,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[25],"class_list":["post-1849","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development","tag-html5"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts\/1849","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/comments?post=1849"}],"version-history":[{"count":2,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts\/1849\/revisions"}],"predecessor-version":[{"id":2315,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts\/1849\/revisions\/2315"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/media\/2304"}],"wp:attachment":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/media?parent=1849"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/categories?post=1849"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/tags?post=1849"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}