Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

338
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!