3

I am using Ajax.

And here is the Ajax-call part of my twig template,

$.post('{{path('acme_member_delScore')}}',               
    {data1: num }, //I assured that 'num' has right data in javascript
    function(response){
        if(response.code == 100 && response.success){//dummy check
          //do something
            console.log(response.id);
        }
}, "json");

And my routing.yml contains,

acme_member_delScore:
    pattern: /delScore
    defaults: { _controller: AcmeMemberBundle:Default:delScore}

While the action in my Controller is defined as follow,

public function delScoreAction()
{
    $request = $this->container->get('request');
    $id = $request->query->get('data1');// but $id is null
 // ...

Do you have any idea why my $id variable (in delScoreAction) is always set to null?

Is there anything I have to check?

1
  • Btw. standard http ok response code is 200. But the check is not neccesary as the funtion is only called on success. Commented Sep 1, 2013 at 19:46

1 Answer 1

4

Try something like this

$id = $request->request->get('data1');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.