0
axios.get('http://192.168.0.103:3000/weather/Hourly?longitude=${coords.longitude}&latitude=${coords.latitude}') .then(result => { console.log(result); dispatch(fetchWeatherDailySucceeded(result.data.weatherInfor)) }) .catch(error => { dispatch(fetchWeatherDailyFailed()); }) 

Somehow the string doesn't recognize my injection and the url send to the server is the whole string with ${}

enter image description here

0

2 Answers 2

1

${} works with `` backticks not with " or '

You need to use `` ( backticks)

`http://192.168.0.103:3000/weather/Hourly?longitude=${coords.longitude}&latitude=${coords.latitude}` 

Or if you use ' or " you can use string concatanation

'http://192.168.0.103:3000/weather/Hourly?longitude=' coords.longitude + '&latitude=' + coords.latitude 
Sign up to request clarification or add additional context in comments.

Comments

1

You cannot inject variables inside '' or "". You should ``.MDN says

Template literals are enclosed by the back-tick (``)

axios.get(`http://192.168.0.103:3000/weather/Hourly?longitude=${coords.longitude}&latitude=${coords.latitude}`) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.