簡體   English   中英

刪除地址Ajax Opencart 2.1.x

[英]Delete address Ajax Opencart 2.1.x

我試圖通過使用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的error塊,並且錯誤顯示如下screeenshot

在此處輸入圖片說明

請提出建議。 並請說明操作pre.customer.delete.addresspost.customer.delete.address如何工作?

您將在響應中返回一個頁面。 這表明您可能遇到404錯誤,另一種錯誤,或者正在調用呈現頁面的函數。 確保所有這些都沒有發生。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM