0

I'm using axios get to fetch data by sending parameter request body and ran into this issue:

enter image description here

console.log("Submitted!");
console.log(latitude);
console.log(longitude);
axios.get('http://127.0.0.1:8000/api/real-estate/apartment-sale-hanoi-price/predict', {
                        
                        "latitude": latitude,
                        "longitude": longitude
                        
                    })
                    .then(response => {
                        predict_price = response.data.predicted_price;
                        console.log("predicted_price: " + predict_price);
                        /*
                        popup_content = popup_content + `<br>` + `Predicted: ` + predicted_price;
                        selected_marker.bindPopup(popup_content).openPopup();*/
                    })
                    .catch(error => console.log(error));

My API endpoint returns a JSON object containing predicted_price. It worked when I tested on Thunder client

enter image description here

I think it may have something to do with how I pass the parameter body in the get request.

Previously I tried data and params props inside axios but still the same error. Something might have gone wrong on the client side.

I tried many different Content-Type like json, form-data... but nothing worked so far!

enter image description here

Could you show me a way to solve this?

William Le
  • 825
  • 1
  • 9
  • 16
  • 2
    Axios does not allow sending body with GET request, see here https://stackoverflow.com/a/54005643/4035948, Thunder Client is using different library which allows body in GET – Ranga Vadhineni Feb 15 '22 at 12:58
  • Thank you very much for your very helpful info. I switched to AJAX anyway! – William Le Feb 15 '22 at 13:02

0 Answers0