R
R
Ruslan2021-12-07 08:18:59
AJAX
Ruslan, 2021-12-07 08:18:59

Why is the request to the controller sent to the wrong folder from the display file in opencart?

Hello!
I am writing a module for adding reviews for opencart 2.3. Now I'm doing the admin part. The controller itself is in the admin/controller/module directory. In the admin panel, I have it displayed in the list of modules and the display opens. But when I try to send a new review from the admin panel (that is, from the .tpl file with the template) using Ajax, it gives an error, because it refers to the index.php?route=extension/module/comments&token=bDh5W6J0Lkkq7R2w84avkCyJdTT8pili:563 directory
Why does it refer to extension? The controller is in a different directory.
Here is the ajax send code:

$('#ret').click(function(){
    $.ajax({
      url: 'index.php?route=controller/module/comments/addComment&token=<?php echo $token; ?>',
      type: 'post',
      data: $('.add_com input[type=\'text\'],.add_com input[type=\'hidden\'],.add_com textarea'),
      dataType: 'json',
      beforeSend: function() {
        console.log($('.add_com input[type=\'text\']'));
      },
      error: function (json) {
        console.log('error');
        console.log(json);
      },
      success: function(json) {
        console.log('added');
        console.log(json);
        location.reload();
      }
    });
    return false;
  });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel, 2021-12-07
@kuchuluk

check the path.
You don't need to put the controller in the path, you are already there.
module/comment is not a valid address for 2.3
extension/module/ is correct. put your module in controller/extension/module/comments/ path
and call accordingly

url: 'index.php?route=extension/module/comments/addComment&token=<?php echo $token; ?>',

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question