尝试使用用户的城市输入(例如洛杉矶)并包含在 Ajax URL 参数中,但是当我 console.log(searchURL)
时。它不会在 "losangels"
之间添加 '+'
,从而破坏 URL。如何使 URL 包含包含两个单词的城市之间的 +
。
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);
});
最佳答案
userCity = encodeURIComponent($("#userCity").val());
关于javascript - 用户输入未正确反射(reflect)在 AJAX URL 调用中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47275524/