Reputation: 43
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);
});
Upvotes: 0
Views: 51
Reputation: 219037
URL-encode the value:
userCity = encodeURIComponent($("#userCity").val());
Upvotes: 2