I am using AJAX to send some variables to a PHP form that will process them and put them into session variables. In the code below, I am trying to get data from two POST variables.
If I leave both as they are, none will work. If I comment out one, the other will work, and vice versa. I'm not sure what I'm doing wrong here.
Here is the AJAX that sends data to the PHP page to be processed:
$.ajax({
type: 'POST',
async: false,
data:
{
from_date: from_date,
job_no: job_no,
},
url: 'pnf_post.php', //send variables to this page to be processed
success: function(data){
oTable2.fnReloadAjax('FE_resolved_pnfs.php'); //reload datatables
},
error: function(){
console.log(data);
alert('Error');
}
});
Here is the code that processes the AJAX data:
session_start();
if(isset($_POST['job_no']))
{
$_SESSION['Job_Num'] = $_POST['job_no'];
$_SESSION['Search_By_Date'] = "NO";
}
if(isset($_POST['from_date']))
{
$_SESSION['From_Date'] = $_POST['from_date'];
$_SESSION['Search_By_Date'] = "YES";
}
Any help would be greatly appreciated
from_date
and job_no
in the post datafrom_date
or job_no
existsSearch_By_Date
first to NO
then to YES
so it's always YES
You might want to check if the value evaluates to true or false instead of using isset
which checks the existence of the key in the array.
@jk. Trailing comma is not a problem for modern browsers.
Take out the comma here:
job_no: job_no,
And change it to:
job_no: job_no
Full snip:
data:
{
from_date: from_date,
job_no: job_no
},