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 :)

    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)