[英]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.