Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

170
Visualizações
Ajax call a php file in Opencart 2

I want to ajax call a php file which i created system/helper which calls for a method of a model which adds a coupon in the database. the php file contains the following.

<?php
function coupon_for_acumba() {
            $this->load->model('total/coupon');

            echo $this->model_total_coupon->coupon_test();
        }

I created a js file which makes the ajax call when a form is submitted. The script in the file is the following

let acumbaForm = document.querySelector('#form-acm_28955');
                acumbaForm.addEventListener('submit', function () {
                    setTimeout(function () {if (document.querySelector('.succes-alert-form-acm')) {
                        $.ajax({

                                url : '/system/helper/acumba.php',
                                type : 'POST',
                                success : function (result) {
                                console.log (result); // Here, you need to use response by PHP file.
                },
                    error : function () {
                        console.log ('error');
            }

                    });
                }}, 2000)
                    
                })

finally i called this js file in catalog/controller/common/header.php with $this->document->addScript('catalog/view/javascript/test1.js');

The problem is that everytime i submit the form i get an error message from the ajax call. Can you tell me what i am doing wrong please?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

OpenCart doesn't allow call PHP files directly from system folder (check .htaccess file in system folder). Try to open https://yoursite/system/helper/acumba.php, You'll get 403 Forbidden. You have to use a route to call a method.

url : '/system/helper/acumba.php', // wrong

You have to modify /catalog/controller/extension/total/coupon.php and put in your method, then call this way in your JS file.

url : 'index.php?route=extension/total/coupon/coupon_for_acumba',
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda