我正在尝试通过使用 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.address
和post.customer.delete.address
工作?