Retrieve ajax data parameter value in .php file
Retrieve ajax data parameter value in .php file
wasimwani
Posts: 19Questions: 5Answers: 0
How does one retrieve value of parameter in .php file passed in javascript file
My js code is like this
(function($){
$(document).ready(function() {
var date= new Date();
var currMonth= date.getMonth();
//alert("Month!!:"+currMonth+1);
var editor = new $.fn.dataTable.Editor( {
"ajax": "php/table.JKBINSR.php",
"table": "#reminder",
"data": {
"currMonth": currMonth
},
"fields": [
......
and my php code is as
<?php
// DataTables PHP library
include( "lib/DataTables.php" );
// Alias Editor classes so they are easy to use
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Join,
DataTables\Editor\Validate;
//$month = $_POST['currMonth'];
//echo $month;
Editor::inst( $db, 'JKBINSR', 'id' )
->fields(
Field::inst( 'accntno' )
->validator( 'Validate::minMaxLen', array( 'empty'=>false, 'min'=>16, 'max'=>16 ) ),
Field::inst( 'accnttitle' )
->validator( 'Validate::notEmpty' ),
Field::inst( 'alias' )
->validator( 'Validate::notEmpty' ),
Field::inst( 'doi' )
->validator( 'Validate::dateFormat', array( 'empty'=>false, 'format'=>'m-d-y' ) )
->getFormatter( 'Format::date_sql_to_format', 'm-d-y' )
->setFormatter( 'Format::date_format_to_sql', 'm-d-y' ),
Field::inst( 'doe' )
->validator( 'Validate::dateFormat', array( 'empty'=>false, 'format'=>'m-d-y' ) )
->getFormatter( 'Format::date_sql_to_format', 'm-d-y' )
->setFormatter( 'Format::date_format_to_sql', 'm-d-y' ),
Field::inst( 'amount' )
->validator( 'Validate::notEmpty' ),
Field::inst( 'POLNO' ),
Field::inst( 'remark' )
)
//->where( $key = null, $value = null, $op = '=' )
->where( $key = 'accntno', $value = '0590020100000042', $op = '=' )
->process( $_POST )
->json();
Here i want to retrieve the value of currMonth . This line of code gives javascript alert "Invalid JSON response..."
//$month = $_POST['currMonth'];
//echo $month;
This discussion has been closed.
Answers
Try
var currMonth= date.getMonth()+1;
then
alert("Month!!:"+currMonth);
Also you can try to start the php code with
if (isset($_POST['currMonth'])) {
echo $month;
}
That should work as a dispatcher. At least this is how I make it work in my code.
@the_champ Well the control never gets inside if(isset($_POST['currMonth'])) , that means the value is never set in currMonth . I am really at wits end as to why its not working
@allan can u please help