【发布时间】:2022-01-25 11:18:26
【问题描述】:
我尝试使用 AJAX(来自管理部分)向管理控制器的方法发出 POST 请求。我的 JS 代码:
<script>
$(".remove-request-btn").on('click', function () {
let request_id = $(this).data('request-id');
let confirm_result = confirm('Are you sure you want to delete this request?');
if (confirm_result) {
$.ajax({
url: 'index.php?route=extension/x_feedback/settings/removeRequest&token={{ token }}',
method: 'post',
dataType: 'json',
data: {request_id: 11},
success: function(data) {
if (data.status === 'ok') {
location.reload();
}
},
error: function () {
alert('Error');
}
});
}
});
</script>
我的方法:
public function removeRequest()
{
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode(
[
'status' => 'ok'
]
));
}
我尝试将管理员添加到 url 中,例如 '/admin/index.php?route=extension/x_feedback/button/feedbackRequest&token={{ token }}' 但这无济于事。你能帮我看看我做错了什么吗?谢谢!
【问题讨论】:
-
在 url 中使用 user_token 而不是 token,如 opencart 3 管理 URL 使用 user_token 而不是旧版本中的 token
标签: php ajax opencart opencart-3