简体   繁体   中英

Delete address Ajax Opencart 2.1.x

I am trying to delete address by using ajax call and data type as json:

Ajax call is as below:

$(".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);
    }
});

and in account/address/delete i wrote a new Post request condition as below:

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));
  }
}

When i execute ajax call then address is deleted successfully but as a reponse the error block of ajax is shown and error says as below screeenshot

在此处输入图片说明

Please suggest. and please explain how operations pre.customer.delete.address and post.customer.delete.address work??

You are getting a page returned in your response. This indicates you might be getting a 404, another kind of error, or are calling onto a function that renders a page. Make sure none of this is happening.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM