gpt4 book ai didi

javascript - 从输入框获取数据并插入到mysql数据库

转载 作者:行者123 更新时间:2023-11-29 19:32:21 25 4
gpt4 key购买 nike

此代码来自 Google API。我想从搜索框“pac-input”获取值,然后插入到 mysql 数据库。如何从输入框中获取值?我已经尝试过 $_GET$_POST$_REQUEST 但没有成功这是来源:https://developers.google.com/maps/documentation/javascript/examples/places-searchbox

<input id="pac-input" class="controls" type="text" placeholder="Search Box" name="pac-input">
<div id="map"></div>
<script>

function initAutocomplete() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -33.8688, lng: 151.2195},
zoom: 13,
mapTypeId: 'roadmap'
});

// Create the search box and link it to the UI element.
var input = document.getElementById('pac-input');
var searchBox = new google.maps.places.SearchBox(input);
map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);



// Bias the SearchBox results towards current map's viewport.
map.addListener('bounds_changed', function() {
searchBox.setBounds(map.getBounds());
});

var markers = [];
// Listen for the event fired when the user selects a prediction and retrieve
// more details for that place.
searchBox.addListener('places_changed', function() {
var places = searchBox.getPlaces();

if (places.length == 0) {
return;
}

// Clear out the old markers.
markers.forEach(function(marker) {
marker.setMap(null);
});
markers = [];

// For each place, get the icon, name and location.
var bounds = new google.maps.LatLngBounds();
places.forEach(function(place) {
if (!place.geometry) {
console.log("Returned place contains no geometry");
return;
}
var icon = {
url: place.icon,
size: new google.maps.Size(71, 71),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(17, 34),
scaledSize: new google.maps.Size(25, 25)
};

// Create a marker for each place.
markers.push(new google.maps.Marker({
map: map,
icon: icon,
title: place.name,
position: place.geometry.location
}));

if (place.geometry.viewport) {
// Only geocodes have viewport.
bounds.union(place.geometry.viewport);
} else {
bounds.extend(place.geometry.location);
}
});
map.fitBounds(bounds);
});
}

</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB9RRjfBs5H4kP7Pa-1SePt6FzrzmC6KX8&libraries=places&callback=initAutocomplete"
async defer></script>

最佳答案

$_GET、$_POST 和 $_REQUEST 仅在表单提交后才起作用。如果你想访问之前输入字段的值,可以直接执行 input.value

关于javascript - 从输入框获取数据并插入到mysql数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41719928/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com