Good day, everybody! I have a small problem here with one of my React apps: I am trying to get the Weather alerts using an API. My App.js file looks like this:
import React, { Component } from 'react';
import './App.css';
import $ from 'jquery';
import Alerts from './Components/Alerts';
class App extends Component {
constructor(){
super();
this.state = {
alerts:[]
}
}
getAlerts(){
$.ajax({
url: 'https://api.weather.gov/alerts/active/zone/AKZ201',
dataType: 'json',
cache: false,
success: function(data){
this.setState({alerts: data});
}.bind(this),
error: function(xhr, status, err){
console.log(err);
}
});
}
componentDidMount(){
this.getAlerts();
}
render() {
return (
<div>
<Alerts alerts={this.state.alerts} />
</div>
);
}
}
export default App;
The problem is that this ajax function is adding an extra parameter at the end of the API URL and because of this extra parameter the API URL doesn't return me the correct data.
This is what I get in my console:
jquery.js:9600 GET https://api.weather.gov/alerts/active/zone/AKZ201?_=1527798208757 400 ()
The extra parameter is ?_=1527798208757 400 ()
I figured it out that this extra parameter is causing the problem. Any ideas how I could remove this parameter?
Thank you!