【发布时间】:2019-03-02 16:08:10
【问题描述】:
我有这样的代码:
<input type="text" id="start" name="o">
<input type="text" id="end" name="d">
<input type="text" id="total" name="total" hidden="hidden">
<button onclick="calcRoute();" value="/index.php?route=information/mymove" >text</button>
<script>
function calcRoute() {
var start = document.getElementById('start').value;
var end = document.getElementById('end').value;
var request = {
origin: start,
destination: end,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
computeTotalDistance(response);
}
});
}
function computeTotalDistance(result) {
var total = 0;
var myroute = result.routes[0];
for (i = 0; i < myroute.legs.length; i++) {
total += myroute.legs[i].distance.value;
}
total = total / 1000.
document.getElementById("total").value = total + " km";
}
</script>
如果我将此代码用于按钮:
<input type="button" value="go" onclick="calcRoute();"> 这会执行 javascript 函数,但不会将数据传递到另一个页面。
我在控制器文件中也有这部分:
if (isset($this->request->post['o'])) {
$data['o'] = $this->request->post['o'];
}
if (isset($this->request->post['d'])) {
$data['d'] = $this->request->post['d'];
}
if (isset($this->request->post['total'])) {
$data['total'] = $this->request->post['total'];
}
【问题讨论】:
-
您应该使用
ajax之类的东西将数据传递到另一个页面。 -
为什么不设置cookie??
-
也许你可以在一个页面中设置一个cookie并从另一个页面访问它?
-
哪个
other page?你指的是index.php?route=information/mymove吗?您需要将数据传递到另一个页面的目的是什么? -
您需要将哪些具体数据发送到其他地方?
标签: javascript php google-maps