I have a select with some values.
When an option is selected I need to use .post
in jQuery to send the selected value to a PHP function to obtain the $_POST
variable on PHP.
Then I can use the variable to evaluate a condition on PHP.
I use CakePHP 2 to create a URL.
To assing the post URL to the numberOption
variable.
$( "#selectFilter" ).change(function() {
var numberOption = "<?php echo $this->Html->url(array('action' => 'returnNumberOption/' ));?>" +
"/" + $( "#selectFilter option:selected" ).val();
$.post(numberOption, function(data){
console.log("Here is the number value of the select "+data);
var phpVariable = "<?php echo $_POST?>"//THIS DONT WORK!
});
});
Using this code I get an unexpected identifier
error.
Question
How can I get the $_POST
variable within the jQuery $.post
call?
var url = "<?php echo $this->Html->url(array('action' => 'returnNumberOption/' ));?>";
var value = $( "#selectFilter option:selected" ).val();
$.post(url,{data: value})
.done(function(data){
console.log("Here is the number value of the select "+data);
var phpVariable = "<?php echo $_POST?>"//THIS DONT WORK!
});
<?php
public function returnNumberOption() {
if ($this->request->is('post')) {
$data = $this->request->data;
}
}