ga-wdi-exercises / pbj-project3

[project]
0 stars 2 forks source link

Trouble for issue for having variable persist down and GET requests now failing #56

Closed edwardpark closed 9 years ago

edwardpark commented 9 years ago

so was working on getting the variables returnLatitude and returnLongitude to persist so that I could use them to input into the variable urlWeather but the return is console.logging as " { }" and all of my .GEt requests are now failing .

screen shot 2015-08-27 at 3 15 02 pm


    // THIS IS FOR MATCHING USER VAL TO DATABASE VAL
    var request = "http://localhost:3000/busstops/";
    $.ajax({
      url: request,
      type: "GET",
      dataType: "json"
    })
    .done(function(response) {
      var busStops = [];
        for(var i = 0; i < response.length; i++){
          busStops.push(new BusStop(response[i]));
          var responseArray = response[i].StopID;
          for (var index = 0; index < responseArray.length; ++index) {
              if (responseArray === stopId) {
                console.log("The entry matches ")
                returnLatitude = response[index].Lat;
                returnLongitude = response[index].Lon;
              }
              else {
                console.log("Not working")
              }
              return {
                returnLatitude:returnLatitude,
                returnLongitude:returnLongitude
              };
          }//end of inner for loop
        }//end of outer for loop
      })
      .then(function(latlon){
          console.log(latlon);
          var urlWeather = "https://localhost:3000/weather/" + returnLatitude + '/' + returnLongitude;
          $.ajax({
            url: urlWeather,
            type: "GET",
            dataType: "json"
          }).done(function(response){
            latitude = response.latitude;
            weather = new WeatherView(response)
            weather.render()//renders each bus number and arrival time.

          }).fail(function(){ //closes ajax done function
            console.log("Oh noooo! It failed!");
          })

        }) //END OF .FAIL AND END OF AJAX CALL
    .fail(function(response){
        console.log("js failed to load");
      });
andrewsunglaekim commented 9 years ago

is the server running for your backend that you're making the GET request too?

edwardpark commented 9 years ago

hey andy yep just double checked

RobertAKARobin commented 9 years ago

Does it work when you just type in the address in your browser?

edwardpark commented 9 years ago

hey thanks guys! burned a set with Jessie and got it solved thanks!