我有自动完成地址谷歌api文本框在我的形式,当我选择地址,我得到在另两个文本框中选择的地址的长度和长度。
现在,当我选择的地址,我想在我的ajax请求中传递的后期和长值,但每次我得到空值。
请帮我走出困境。
<?php
echo $this->Form->input('from_address', array('required' => false,'label' => false, 'div' => false,
'placeholder' => 'Enter from address', 'class' => 'form-control','id' => 'fromaddress'));
?>
<?php echo $this->Form->input('from_lat', array('id' => 'fromlat')); ?>
<?php echo $this->Form->input('from_long', array('id' => 'fromlong')); ?>
<script type="text/javascript">
$("#fromaddress").on('change', function() {
ajaxRequest = $.ajax({
url: '<?php echo Router::url(array("controller" => "Orders", "action" => "searchCourier")); ?>',
type: 'POST',
data: {
frmlat: $("#fromlat").val(),
frmlong: $("#fromlong").val()
},
dataType: "html",
success: function(response) {
$("#courier_locations").html(response);
},
complete: function() {
$('.spinicon').hide();
}
});
});
</script>
你可以调用你的ajax改变纬度和纬度
$("#fromlat").on('change', function() {
ajaxRequest = $.ajax({
url: '<?php echo Router::url(array("controller" => "Orders", "action" => "searchCourier")); ?>',
type: 'POST',
data: {
frmlat: $("#fromlat").val(),
frmlong: $("#fromlong").val()
},
dataType: "html",
success: function(response) {
$("#courier_locations").html(response);
},
complete: function() {
$('.spinicon').hide();
}
});
});