简体   繁体   English

在更改或文本框离开时在php中的ajax请求中发布文本框值

[英]post textbox values in ajax request in php on change or textbox leave

I have autocomplete address google api textbox in my form and when i select address i get the lat and long of selected address in another two textbox. 我在表单中有自动完成地址google api文本框,当我选择地址时,在另外两个文本框中得到了所选地址的经纬度和经度。

now when i select the addreess i want to pass the lat and long value in my ajax request also but every time i am getting null values. 现在,当我选择addreess时,我也想在我的ajax请求中传递纬度和经度值,但是每次我得到空值时。

please help me to go out of this. 请帮我解决这个问题。

<?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>

you can call your ajax on change of lattitude and langitude dropdown 您可以在纬度和经度下拉列表更改时调用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();
    }
});

}); });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM