0

Value changed to null in ajax after updating the shipping city value from text field. I don't known what is the problem.. please help me Friends.

my php code:

 public function updateshippingcity() {

  if ($this->request->server['REQUEST_METHOD'] == 'POST') 
   {
      $json['new_shipping_city'] = $this->request->post['shipping_city'];


     $this->db->query("UPDATE " . DB_PREFIX . "order SET shipping_city = '" . $this->db->escape($this->request->post['shipping_city']) . "' WHERE order_id = '" . (int)$this->request->get['order_id'] . "'");


     $this->response->setOutput(json_encode($json));
  }

}

my ajax code :

<script type="text/javascript">
$("#update-shipping-city").click(function() {
    var name_val = $('input[name="new_shipping_city"]').val();
    $.ajax({
        url: 'index.php?route=sale/order/updateshippingcity&token=<?php echo $token; ?>&order_id=<?php echo $order_id; ?>',
        type: 'post',
        dataType: 'json',
        data: {
            shipping_city: name_val
        },
        beforeSend: function() {
            $('#update-shipping-city').attr('disabled', true);
        },
        complete: function() {
            $('#update-shipping-city').attr('disabled', false);
        },
        success: function(json) {

        }
    });
    alert("shipping city has changed");
});

my html code:

<div class="col-md-12">
    <input  name="new_shipping_city" value="<?php echo $shipping_city; ?>"></input>
    <button id="update-shipping-city" > update </button>
</div>
Ask Xah
  • 237
  • 2
  • 13

1 Answers1

0

I had achieved finally by post method.

<script type="text/javascript">
$(function() {
    $("#update-shipping-city").click(function(e) {
        e.preventDefault();
        var scity_val = $('input[name="new_shipping_city"]').val();
        $.post("index.php?route=sale/order/updateshippingcity&token=<?php echo $token; ?>&order_id=<?php echo $order_id; ?>", {
            shipping_city: scity_val
        }, function(data, status) {
            alert("Data: " + data + "\nStatus: " + status);
        });
    });
});

Finally, my problem cleared. thank guys for contributing on my question :)

Ask Xah
  • 237
  • 2
  • 13