Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6553699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:36:48+00:00 2026-05-25T12:36:48+00:00

Via jquery, I ajax/POST this json {indices:[1,2,6]}: to a symfony2 action. Right now I

  • 0

Via jquery, I ajax/POST this json

{"indices":[1,2,6]}:

to a symfony2 action. Right now I only really care for the array, so if this makes things considerably easier I could just post [1,2,6] as well.

How can I convert this to a php object?


Somehow, this does not work:

/**
 * @Route("/admin/page/applySortIndex", name="page_applysortindex")
 * @Method("post")
 * @Template()
 */
public function applySortIndexAction()
{
    $request = $this->getRequest();
    $j = json_decode($request->request->get('json'));
    $indices = $j->indices;
    return array('data'=> $indices);
}

gives a

Notice: Trying to get property of non-object in …/PageController.php line 64 (500 Internal Server Error)

which would be where I access $j->indices, where $j seems to be null


The poster:

$.ajax({
      type: 'POST',
      url: "{{ path('page_applysortindex')}}",
      data: $.toJSON({indices: newOrder}),
      success: ...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:36:48+00:00Added an answer on May 25, 2026 at 12:36 pm

    To get the data sent via body use:

    $request = $this->getRequest();
    $request->getContent();
    

    inspect the output and then act upon. but this will contain the json.

    (yep, tested it. this leads to your json)


    getting a POST-parameter with name json from within a controller:

    $request = $this->getRequest();
    $request->request->get('json');
    

    Request-object


    $j = json_decode('{"indices":[1,2,6]}');
    
    var_dump($j);
    

    leads to:

    object(stdClass)#1 (1) {
      ["indices"]=>
      array(3) {
        [0]=>
        int(1)
        [1]=>
        int(2)
        [2]=>
        int(6)
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a post via Jquery ajax that looks like this: $.ajax({ type:
I'm passing an object from jQuery to a MVC3 Controller via a $.ajax POST.
I'm using Symfony 1.4. I'm posting a form via Jquery ajax to an action
I have a web service that returns this string via the jQuery $.ajax() call
I'm using jQuery 1.8.2 to call some backend server api's via jQuery's ajax POST.
I've been trying to get this really simple example of using AJAX with JQuery
I am trying to POST a raw string via jQuery.ajax() e.g., contact_list=352345 I have
I've tried doing this via jQuery/ajax but it wasn't working so I thought I'd
I send a form via jquery ajax. I do not only want to send
I am trying to pull in information from Asana API via JQuery.ajax() method. But

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.