0

我正在尝试通过使用 ajax 调用和数据类型作为 json 来删除地址:

Ajax 调用如下:

$(".delete a").on('click', function() {
    url: 'index.php?route=account/address/delete',
    type: 'post',
    data: "address_id="+addid,
    dataType: 'json',
    success: function(html) {
        $("#msg").html('Deleted Address Successfully '); 
    },
    error: function(xhr, ajaxOptions, thrownError) {
        delcheckbox.html('<i class="fa fa-trash-o"></i>');
        alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
    }
});

并在account/address/delete我写了一个新的 Post 请求条件如下:

public function delete() {
  /* Opencart Pre written functions are here */
  if (isset($this->request->post['address_id'])&&$this->validateDelete()) {
      $json = array();
      $this->model_account_address->deleteAddress($this->request->post['address_id']);
      /* Unset Session variables same as get function of opencart */

      /*to get json as response*/
      $this->response->addHeader('Content-Type: application/json');
      $this->response->setOutput(json_encode($json));
  }
}

当我执行 ajax 调用时,地址被成功删除,但作为响应,error显示了 ajax 块并且错误显示如下屏幕截图

在此处输入图像描述

请建议。并请解释如何操作pre.customer.delete.addresspost.customer.delete.address工作?

4

1 回答 1

0

您的响应中返回了一个页面。这表明您可能会收到 404、另一种错误,或者正在调用呈现页面的函数。确保这一切都没有发生。

于 2016-04-10T05:08:23.050 回答