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

342
Visualizações
PHP MVC & AJAX - AJAX does not call function from controller

So I am trying to learn AJAX requests, and in testing purposes, I am trying to use it in my personal project. I set up some test functions here and there, to test out how I can use AJAX in my project, and I got on an issue.

I'm making an AJAX call from script tags in my html, but it appears to just return all the html of that page.

AJAX call code is:

            $.ajax({
            URL: "<?php echo URLROOT;?>tasks/setcompleted",
            type: "GET",
            data: {id:'3'},
            contentType: "application/json; charset=utf-8",
            success: function(res){
                console.log(res);
            }
        });

PHP Tasks controllers method setcompleted() code is just a simple echo of data passed from AJAX request via GET:

        public function setcompleted(){
            if(isset($_GET['id'])){
                echo $_GET['id'];
            }
        }

I did some research, and found similar questions here, that suggested to check the URL that is passed to AJAX request. I did that, the URL that is passed in AJAX request is correct and works, if I manually write it into browser and add necessary parameters for the GET.

Can anyone suggest what am I doing wrong here?

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

0

Your function returns nothing.

public function setcompleted()
{
    if(isset($_GET['id']))
{
    $output = json_encode($_GET['id']);
 }
          return $output;
    }
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