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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀