[英]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.address
和post.customer.delete.address
如何工作?
您将在响应中返回一个页面。 这表明您可能遇到404错误,另一种错误,或者正在调用呈现页面的函数。 确保所有这些都没有发生。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.