Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

352
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda