【发布时间】:2021-05-23 11:21:35
【问题描述】:
我有一个 index.php,我从中访问 noun_phrase.php 以返回一个变量。现在我必须将返回的变量从 noun_phrase.php 传递到另一个 php 文件 placeapi.php 以执行某些任务。
index.php
if(dialog.indexOf("restaurant")!=-1 ){
$.ajaxSetup({async: false});
showText="";
sayText="";
$.ajax({
url: "noun_phrase.php",
data: {text: dialog},
success: function(data) {
nlp = data;
findPlace(nlp);
}
});
}
function findPlace(x){
name = x;
$.ajax({
url: "placeapi.php",
data: {text: name},
success: function (data){
}
});
}
placeapi.php
<!DOCTYPE html>
<html>
<head>
<title>Place searches</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCmrjT6f4nt15qV-L9MRWL43TgucZzJHCw
&libraries=places"></script>
<script>
var map;
var infowindow;
function initialize() {
var city = new google.maps.LatLng(-42.882391,147.328591);
map = new google.maps.Map(document.getElementById('map-canvas'), {
center: city,
zoom: 15
});
var request = {
location: city,
radius: 500,
types: ['hotel']
};
infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
service.nearbySearch(request, callback);
}
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
createMarker(results[i]);
}
}
}
function createMarker(place) {
var placeLoc = place.geometry.location;
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(place.name);
infowindow.open(map, this);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas">
</div>
</body>
</html>
我想将从 noun_phrase.php 检索到的数据传递给 placeapi.php 的 javaScript 函数并获取位置,以便我可以在某处显示
【问题讨论】:
标签: javascript php html jquery css