Reminder : $.ajax() – Passing variables with Ajax and PHP using JQuery

1. Create ajax.php

<?php

if ($_SERVER[‘REQUEST_METHOD’] === ‘POST’) { //Check if method used is GET or POST 🙂
$n1 =$_POST[‘newvar1′].’ welcome to php’;
$n2 =$_POST[‘newvar2’] + 20500;
$n3 =$_POST[‘newvar3′].’ goodbye to php’;
}else{
$n1 =$_GET[‘newvar1′].’ welcome to php’;
$n2 =$_GET[‘newvar2’] + 20500;
$n3 =$_GET[‘newvar3′].’ goodbye to php’;
}

echo $n1.’-‘.$n2.’-‘.$n3;   //this will be returned as data to the ajax calling function

?>

Continue reading “Reminder : $.ajax() – Passing variables with Ajax and PHP using JQuery”

Up ↑

%d bloggers like this: