Answer the question
In order to leave comments, you need to log in
Redirect to js, we take data from the server via json. How?
Good afternoon.
Opencart 3
1. We take the url value for the redirect and pass it to the controller via post.
2. From the controller we pass the value of the required url like this:
$json['redirect'] = $this->request->post["redirect"];
function () {
if (json['redirect']) {
location.href = json['redirect'];
}
}
Answer the question
In order to leave comments, you need to log in
Don't get your hopes up that the PHP language will be implemented in JS. If you catch parameters in PHP, then redirect on it and do:
To transfer data to the face of PHP, you need to transfer them correctly.
header("Location:[url]");
The bottom line is that when filling out the form and clicking on the button, the data is transferred to the controller via js code.
$.ajax({
url: 'index.php?route=extension/module/test',
type: 'post',
data: $('#test2 input[name=\'test3\'], #test2 input[name=\'redirect\']'),
dataType: 'json',
$json['redirect'] = $this->request->post["redirect"];
location.reload();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question