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

144
Views
Ajax calling PHP and getting Return value

Not used Javascript -> Ajax -> PHP -> Javascript before and I am struggling to pick-up the return value. Ajax is calling the PHP, but all I am getting back is the HTML for the web page. Can anyone see what I am doing wrong?

Javascript: -

onChange: function(value, text, $selectedItem) {
    jQuery.ajax({ url : 'index.php', type : 'post', data : { action: 'getTest', param : text },
                    success: function(result){
                      console.log('Sucess',result);
                    },
                      failure: function(result){ console.log('Failed'); }
                    });
}

PHP: -

$_action = isset($_Post['action']) ? $_Post['action'] : '0';
if ($_action == 'getTest') {
  $test = $_Post['param'];
  echo $test;
  exit;
}

As I said, RESULT just seems to contain the page's HTML and not the expected string value.

Thanks

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Your post variable is with small caps letters. However the Variable should be full caps ($_POST). So your php is not going into the if statement.

https://www.php.net/manual/en/reserved.variables.post.php

To debug these kind of issues start logging variables like $_action and check if their value is what you expect it to be. Then check if the if statement actually fires, etc. until you find the error.

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!