9
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

axiosでサクっとJSONP

Posted at

今までNative Fetch勢だったのですが、とあるきっかけでaxiosを使ってみたら便利だったので、最近は何かと重宝してます。

そして今回のお題ですが、簡単に扱えるaxiosのJSONP拡張を見つけたのでざっくり紹介です。

ズバリ

NodeとBrowserの両対応です。

Node
const axios = require("axios");
const axiosJsonpAdapter = require("axios-jsonp");
Browser
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/axios-jsonp/dist/index.min.js"></script>
共通
// /path?name=foo&cb=*** の場合
// コールバック関数名は自動生成

axios.get("/path", {
    adapter: axiosJsonpAdapter,
    callbackParamName: "cb",
    params: {
        "name": "foo"
    }
})
// .then()...
9
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?