0

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
asked Jul 19, 2014 at 14:59
1
  • Have you tried to use a client like SOAP UI to query the web service and see what it returns? Commented Jul 19, 2014 at 15:02

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.