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 Pyqt 如何正确的关掉Qthread,并且释放其中的锁?
  • ¥30 网站服务器通过node.js部署了一个项目!前端访问失败
  • ¥15 WPS访问权限不足怎么解决
  • ¥15 java幂等控制问题
  • ¥15 海湾GST-DJ-N500
  • ¥15 氧化掩蔽层与注入条件关系
  • ¥15 Django DRF 如何反序列化得到Python对象类型数据
  • ¥15 多数据源与Hystrix的冲突
  • ¥15 如何在线硕士了解,广告太多,希望有真实接触过的人回答下?(标签-学习|关键词-在线硕士)
  • ¥15 zabbix6.4与frp如何进行联动