Answer the question
In order to leave comments, you need to log in
What's wrong with this code? It seems to refer to google's json and should collect information, but input doesn't work?
The site has input
<input type="text" class="search-input" required="required" value="" placeholder="Введите место события" />
function makeSearchGoogle() {
var searchInput = $('.search-input').val();
if (searchInput) {
var sessionToken = getSessionToken();
var string = searchInput + '&sessiontoken=' + sessionToken + '&key=AIzaSyCSL1_nsETBMG-E3_7Yk2N7wF5kZikNZZI';
$.ajax({
url: 'https://maps.googleapis.com/maps/api/geocode/json?address=' + string + '&key=AIzaSyCSL1_nsETBMG-E3_7Yk2N7wF5kZikNZZI',
method: 'get',
dataType: 'json',
beforeSend: function() {
$b.addClass('is-searching');
},
complete: function(d) {
$b.removeClass('is-searching');
if (typeof d.responseJSON.predictions != 'undefined' && d.responseJSON.predictions.length) {
var data = d.responseJSON.predictions;
var html = '';
var firstId;
$.each(data, function(k, v) {
if (k < 6) {
var parts = v.description.split(', ');
var name = parts[0];
parts.shift();
var other = parts.join(', ');
var active = k == 0 ? ' active' : '';
firstId = v.place_id;
html = html + '<div class="suggestion' + active + '" data-place="' + v.place_id + '">' + ' <b>' + name + '</b>' + (other ? ', ' : '') + other + '</div>';
}
});
$('.suggestions > div').html(html);
if (html == '') {
$('.suggestions').removeClass('show');
} else {
if (setIfLoads && firstId && typeof getStarmapDetails != 'undefined') {
getStarmapDetails(firstId);
}
if (makePick) {
makePick = false;
$('.suggestions').removeClass('show');
$('.suggestion').eq(0).click();
} else {
$('.suggestions').addClass('show');
}
}
setIfLoads = false;
}
}
});
}
}
Answer the question
In order to leave comments, you need to log in
You don't have an event handler for this input in your script, like this:
document.querySelector('.search-input').addEventListener('change', makeSearchGoogle);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question