weixin_33698043 2018-04-20 15:35 采纳率: 0%
浏览 42

在ajax中将值更改为null

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>
  • 写回答

1条回答 默认 最新

  • 游.程 2018-04-20 19:00
    关注

    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 + "
    Status: " + status);
            });
        });
    });
    

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

    评论

    报告相同问题?

    悬赏问题

    • ¥20 求各位能用我能理解的话回答超级简单的一些问题
    • ¥15 yolov5双目识别输出坐标代码报错
    • ¥15 这个代码有什么语法错误
    • ¥15 给予STM32按键中断与串口通信
    • ¥15 使用QT实现can通信
    • ¥15 关于sp验证的一些东西,求告知如何解决,
    • ¥35 关于#javascript#的问题:但是我写的只能接码数字和字符,帮我写一个解码JS问题
    • ¥15 prophet运行报错,如何解决?
    • ¥15 用GPU跑pytorch搭建的LSTM的时候出现了奇怪的报错
    • ¥20 前端数据是从session等作用域拿到的,如何取值继续传递后端呢