How to work with AJAX and SLIM?

plz
i need example how to work with ajax and slim
with rout and the classes

tahnks:)

Route can be any route you want, although it makes sense to group Ajax functions into an AjaxController and give all Ajax entry points a path like

/ajax/yourFunc

The important thing when dealing with Ajax is to return a JSON response like this:

return $response->withJson ([ 'error'=>1, 'errorCode'=>'InvalidID' ], 200);

All in all, it’s quite easy.

im sorry i not understand
plz u can do exmple with a parametrs? (in the class and in the AJAX and where i put that ajax)

tahks alot

This is not easy, because I use my own framework which has a lot of stuff built-in and it won’t make sense if I just copy/paste it. But here’s what an ajax controller function looks like:

public function setAdminMenu (Request $request, Response $response, $args)
{
    $id = Input::fromPost ('id'); 
    if (!$id) {
        return $response->withJson ([ 'error'=>1, 'errorCode'=>'InvalidID' ], 200);
    }

    // do something here ...

    $rc = [ 'success'=>1 ];
    return $response->withJson ($rc, 200);
}

You can map an Ajax request to a controller function like any other route. Hopefully this helps.