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

126
Views
jQuery ajax not working when trying to call php function

I'm trying to call php function from my JavaScript script. I've read several questions on how to call a php function using jQuery ajax. I simply copied most of the content and adapted it to fit my script, but somehow it's not working.

Here's my code:

    var var1 = document.getElementById("tag").value;
    var id = tag.id;
    var var3 = tag.checked;
    var test = $.ajax({
        url: '../PHP/phpFunc.php',
        type: 'GET',
        data: {param1: var1, param2: id, param3: var3},
        complete: function() {
            if(window.console) {
                console.log("success");
            }
        },
        error: function() {
            if(window.console) {
                console.log("Error");
            }
        }
    })

and the php code:

<?php

echo "<script>
     console.log(\"test\")
     </script>";
    $var1= $_GET['param1'];
    $var2 = $_GET['param2'];
    $var3 = $_GET['param3];
    $var4 = '../XML/user/'. $username .'.xml';
   
    //some things are done here 

?>

the "success" is being printed when the JS function is executed, but php code never returns the desired output.

about 4 years ago · Juan Pablo Isaza
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!