S
S
snezhanan2015-12-13 22:29:48
symfony
snezhanan, 2015-12-13 22:29:48

How to pass post via ajax for new routing in Sonate?

Created a new route

protected function configureRoutes(RouteCollection $collection)
    {
        $collection->add('ajax', '/ajax', array(), array(), array(), '', array(), array('POST'));
    }

Sending data via ajax
$.ajax({
                    type: "POST",
                    dataType: 'json',
                    url: "/hrm/hrm/reminder/reminder/ajax",
                    data: {number: $('#numberReminder').val()},
                    cache: false,
                    success: function(res){
                         console.log(res.message);
                    },
                    error: function(error){
                        console.log(error);
                    }
                });

in controller trying to get data
public function ajaxAction(Request $request){
        $number = $request->get('number');
        ...
}

Gives an error message
No route found for "POST /hrm/hrm/reminder/reminder/ajax"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis, 2015-12-14
@prototype_denis

Read the doc, ask Google questions first.
Learn to search for information.
symfony.com/doc/current/book/http_fundamentals.htm...
https://sonata-project.org/bundles/admin/master/do...

// ...
use Sonata\AdminBundle\Route\RouteCollection;
protected function configureRoutes(RouteCollection $collection)
{
$collection->add('clone', $this->getRouterIdParameter().'/clone');
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question