1

My NodeJS Code. I am getting correct result in console but page is not redirected to listings page

function displayCities(cname) {
    var pageData = {
      title: "Listings",
      cities: null
    };
    axios(
      //the request
      {
        url: "https://sandbox.repliers.io/listings?city=" + cname,
        method: "GET",
        headers: {
          'Content-Type': 'application/json', 
          'REPLIERS-API-KEY': 'SKoKOGhEO42QzdkZ1cowKgLGm2mwm4'
        }
      }
    ).then(function (response){
      //on success do stuff
      console.log(response.data);
      pageData.cities = response.data; //store JSON results in pageData.cities (previously null)
      res.render("listings", pageData);
    }).catch(function (error){
      console.log(error);
    });
  }
1
  • 1
    Is this your full code?? Where this function displayCities is being called?? In this code, the definition for res can't be seen anywhere. Commented Mar 26, 2022 at 20:29

1 Answer 1

2

You have not passed the res object to the function.

To be able to access methods of the res object, you should add it to the function signature and give it to the function where you call it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.