删除地址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 调用时,地址被成功删除,但作为响应,显示 ajax 的 error
块,错误提示如下屏幕截图
求推荐。
请解释操作 pre.customer.delete.address
和 post.customer.delete.address
是如何工作的??
您的回复中返回了一个页面。这表示您可能收到 404(另一种错误),或者正在调用呈现页面的函数。确保 none 发生这种情况。
我正在尝试使用 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 调用时,地址被成功删除,但作为响应,显示 ajax 的 error
块,错误提示如下屏幕截图
求推荐。
请解释操作 pre.customer.delete.address
和 post.customer.delete.address
是如何工作的??
您的回复中返回了一个页面。这表示您可能收到 404(另一种错误),或者正在调用呈现页面的函数。确保 none 发生这种情况。