The Slim Framework support forum has moved to http://discourse.slimframework.com. This Tender forum is no longer maintained or monitored.

Problem with getParsedBody

mkarpins's Avatar

mkarpins

10 Feb, 2016 07:49 PM

On my client side I am posting data using jquery:

   $.post("/api/v1/map", JSON.stringify(mapInfo));

mapInfo is a json object.

On server side I have:

$app->post('/meeting/{meetingId}/map', function ($request, $response, $args) {
    $mapInfo = $request->getParsedBody();
 /*
    Now here I am unable to access any of the proeprties using array accessor:
     for example $mapInfo['name'']  returns nothing.
    $mapInfo object is not null itself though
*/ 
});

Am I missing something? The documentation says that getParsedBody should return an array.
However I found out that I have to explicitly invoke (which again followinf the documentation should be done under the hood by

$mapInfo json_decode($request->getBody(), true);

in order to be able to have my

  1. 1 Posted by mkarpins on 10 Feb, 2016 07:50 PM

    mkarpins's Avatar

    Well the problem in fact lied in jquery $.post not properly setting content-type to application/json.

    I had to use $.ajax instead

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac