I\'m trying to do a GET request on wikipedia API. Using jQuery as below works fine:
$.ajax({
url: \'https://en.wikipedia.org/w/api.php?format=json&acti
Ran into the problem in a React Application
Axios doesn't support JSONP they offers alternatives to perform jsonp requests:
Follow this link to see some documentation for jsonp for axios: axios: https://github.com/mzabriskie/axios/blob/master/COOKBOOK.md#jsonp
Here is my documentation:
Step 1: $ npm install jsonp --save
Step 2:
import jsonp from 'jsonp';
(this goes at the top of your component)
Step 3: Create a method in your React Component:
JSONP () {
jsonp( "https://*YourUrlHere.jsonp", { name: 'Name Of JSONP Callback Function' }, (error, data) => {
if (error) {
this.setState({
error,
});
} else {
this.setState({
data: data,
});
}
});
}