Registry / testing / axios-jsonp

axios-jsonp

JSON →
library1.0.4jsnpmunverified

A JSONP adapter for Axios that provides a drop-in replacement for XHR-based requests, supporting promises, cancellation, and a familiar API. Version 1.0.4 is the latest stable release; the package is in maintenance mode with infrequent updates. It is the de facto standard for JSONP with Axios, offering minimal configuration via `callbackParamName` and seamless integration with Axios interceptors and error handling. Unlike custom JSONP implementations, it reuses Axios's promise and cancellation patterns, reducing boilerplate.

npm install axios-jsonp
INSTALL
IMPORT
SIG · AXIOS-JSONP
A
axios-jsonp
testingjavascriptv1.0.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (jsonpAdapter)
import jsonpAdapter from 'axios-jsonp';
const axiosJsonp = require('axios-jsonp');
The package has a CommonJS default export; ESM import syntax works with bundlers. The default export is the adapter function.
axios.create with adapter
const instance = axios.create({ adapter: jsonpAdapter });
axios({ url: '/endpoint', adapter: 'jsonp' })
The adapter is passed as an object, not a string. Common mistake: using string 'jsonp' instead of the imported function.
callbackParamName option
axios({ url: '/endpoint', adapter: jsonpAdapter, callbackParamName: 'callback' })
axios.get('/endpoint', { params: { callback: 'handleResponse' } })
Specify callback parameter name via adapter option, not URL params. Default is 'callback'.

Demonstrates creating a JSONP request with Axios using the adapter, including error handling and timeout.

import axios from 'axios'; import jsonpAdapter from 'axios-jsonp'; async function fetchData() { try { const response = await axios({ url: 'https://api.example.com/data', adapter: jsonpAdapter, callbackParamName: 'callback', timeout: 5000 }); console.log(response.data); } catch (error) { console.error('JSONP request failed:', error); } } fetchData();
Debug
Known issues
gotchaJSONP only supports GET requests; POST or other methods will fail silently or throw errors.
fix
Ensure all JSONP requests use GET method. Use Axios's 'method' field or default GET behavior.
affects: >=0.0.0
gotchaThe adapter does not work in Node.js environments because JSONP relies on browser <script> tags.
fix
Use only in browser environments. For Node.js, consider a JSONP polyfill or purely server-side data fetching.
affects: >=0.0.0
deprecatedThe package is in maintenance mode and may not be actively updated for future Axios versions.
fix
Consider migrating to Fetch API with a JSONP wrapper or CORS-enabled endpoints.
affects: >=1.0.0
gotchaCancellation via CancelToken requires Axios's CancelToken; AbortController is not supported.
fix
Use Axios's CancelToken for cancellation. Example: const source = axios.CancelToken.source(); axios({ cancelToken: source.token, adapter: jsonpAdapter });
affects: >=0.0.0
Errors
Common errors & fixes
Error: Network Error
JSONP request failed due to script loading error (e.g., network failure, invalid response).
fix
Check the URL is correct and the server supports JSONP. Use browser DevTools to verify the script tag is appended and the response is valid.
TypeError: adapter is not a function
The imported jsonpAdapter is undefined or not a function, often due to incorrect import.
fix
Ensure correct import: `import jsonpAdapter from 'axios-jsonp'`. For CommonJS: `const jsonpAdapter = require('axios-jsonp').default` or check module system.
Uncaught ReferenceError: callback is not defined
The server response calls a callback function that does not exist globally.
fix
The adapter automatically creates a global callback function named after the callbackParamName. Ensure the callbackParamName matches what the server expects. Default is 'callback'.
Upgrade
Version history
1.0.4latest on npm
Audit
Dependencies
axiosrequiredThis is an adapter for Axios; Axios must be installed separately, although it is listed as a peer dependency in some versions.
Agent activity
18 hits · last 30 days
node
16
Amazon
1
OpenAI (training)
1
Resources
axios-jsonp — npm install axios-jsonp · libregistry