0

Trying to use user's city input (ex. Los Angeles) and include in Ajax URL parameters, however when I console.log(searchURL). It doesn't add a '+' between "los angels" thus breaking the URL. What can be done to make the URL include the + between cities with two words.

var apiKey = "&client_id=OTU3MDMwMHwxNTEwMjUwNDQ0LjI3"
var baseQueryURL = "https://api.seatgeek.com/2/events?" + apiKey;
console.log(baseQueryURL);

function runSearch(queryURL) {
  $.ajax({
      url: queryURL,
      method: 'GET'
    }).done(function(response) {
        console.log(response);
      };

      $("#submitSearch").on("click", function(event) {
        //prevents default event from occuring
        event.preventDefault();

        userCity = $("#userCity").val();
        console.log(userCity);
        //create variable queryCity to hold city queried with URL parameters
        var queryCity = "&venue.city=" + userCity;
        //create searchURL to pass in as queryURL in AJAX call
        searchURL = searchURL + queryCity;
        console.log(searchURL);
        runSearch(searchURL);
      });

2 Answers 2

2

URL-encode the value:

userCity = encodeURIComponent($("#userCity").val());
Sign up to request clarification or add additional context in comments.

Comments

-1

I've used this:

userCity.split(" ").join("+")

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.