I am trying to get the id, where the user clicked, and pass it to my controller via AJAX. For some reason, when i try to show what i am receiving in my controller, it show an empty array.
Any idea why my alert return an empty Array?
JS Function:
function categorySelected(elem) {
$.ajax({
url: "/newgallery/creative-fields-click",
type: "POST",
data: elem.id
}).done(function (response) {
alert(response);
});
}
PHP:
public function creativeFieldsClickAction()
{
$idSelected = $this->_request->getPost();
print_r( $idSelected );
exit();
}
cookie monster
11k4 gold badges34 silver badges45 bronze badges
-
Have you tried to use a client like SOAP UI to query the web service and see what it returns?codea– codea2014年07月19日 15:02:43 +00:00Commented Jul 19, 2014 at 15:02
2 Answers 2
Data should be JSON, not integer.
data: { elemid : elem.id }
Then in PHP data can be found from $_POST['elemid']. In your code it could be like
$this->_request->getPost()['elemid'];
Or something like that.
answered Jul 19, 2014 at 15:04
Elias Kosunen
4437 silver badges20 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Try by changing
In ajax
data: { id : elem.id }
And in action of controller
$ids = $_POST;
print_r($ids);
answered Jul 19, 2014 at 15:08
MH2K9
12.1k7 gold badges34 silver badges49 bronze badges
Comments
default