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();
}
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.

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);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.