Pass variable from .js to .php not working
Pass variable from .js to .php not working
Rpgccv
Posts: 10Questions: 3Answers: 0
Here is my "table.something.js'
var test = datatest;
$.ajax({
url: 'php/table.something.php',
type: 'POST',
data: ({
test: test
}),
success: function (data) {
}
});
And here is my "table.something.php'
$idNumber = $_POST['test'];
// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'table' )
->fields(
Field::inst( 'column_id' ),
Field::inst( 'text' ),
Field::inst( 'registertime' ),
Field::inst( 'changedtime' )
)
->where('table.column_id', $idNumber)
->process( $_POST )
->json();
Why is not passing the variable!?
If i change to $idNumber = 1
or any other number, it work great.
Any suggestion!?
Thanks ;-)
This discussion has been closed.
Answers
Assuming that
datatest
is set to be 1, then it looks like$idNumber
should also be 1.If you have a link to the page showing the issue I'd be happy to take a look.
Allan
That is correct,
datatest
is set to be 1 or any number, but nothing works.This is the error:
"DataTables warning: table id=table_id - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1"
Am i putting the variable
$idNumber = $_POST['test'];
in the right place!?What is the server returning if it isn't valid JSON? Is there an error message in there saying what is going wrong? If the response is empty, you'll need to check your server's error logs.
Allan
on the error's log the error is "...Undefined index: test..."
I can pass that variable to any other .php file, just not this one or any other alike from the "Datatables" so there is a problem there.
I see on this forum more people with the same problem and they didn´t solve it...
Can you, please, show me something like this working!?
This shows your Ajax request works fine, and I don't see anything wrong with your PHP code. As such, can you link to the page you are having a problem with, and also show me your full PHP code so I can offer some help?
Allan
Thanks for your help, but your example is not helping...
i´m saying that i thing the problem is on datatables - table.something.php, since i can send any variable with ajax anywhere else, but not to that unique file.
This is all php code:
I wouldn't bother assigning the
$idNumber
variable - just use:I can't see any reason why that wouldn't work with the Ajax request from my post above - I can see in the Chrome inspector that the
test
parameter is being sent.Try doing
print_r( $POST );
in your PHP. It will cause a JSON parsing error on the client-side, but that doesn't really matter for a quick check - use the Network inspector in your browser to check what the response from the server is.Allan
The same...That is correct; I'm sure the
test
is being sent... the problem is that it's not received from that file.With you change,... still the same.
I'll post something online so you can access and see!! Can i contact you directly!?
Yes - you can drop me a PM by clicking my name above and then the "Send message" button.
Allan
Try to use use
$_REQUEST instead of $_POST
in the php file. If thats not working try this
instead of data parameter