jquery - Calling a controller function through a button -


I have a problem using Symphony 2 and requests I am reading some docs but it only confuses me Can you clear this easy thing for me? Thank you.

I am creating a website with some articles that a user can add to their favorites. All institutions are fine, mapping and base too. I just have problems in front

I want a button on the article page that calls a function in my controller (which says the correct repository method) and does not refresh the page (This is why I can not only use PHP If the call works then I am thinking about changing the button color.

What do you use for this?

Thanks

You want to use here, jQuery is .

The U needs a route in context:

  / * * * @ Root ("/ do_something", name = "your_action_route") * / Public function doSomethingAction (Request $ request) {  

And then you can script ad JS in your twig template:

  $ (document) .on (click) ',' Button ', function () {$ .ajax (' {{path ('your_action_route')}}, {data: {// You can pass some parameters here for the controller}, success: function (data ) {// change button color}, error: function () {// show warning or something }}; Return False; // This prevents the normal button behavior from executing;});   

In this way, whenever you click a button on your site, the AJAX request will execute your operation in the controller.

Comments

Popular posts from this blog

python - Writing Greek in matplotlib labels, titles -

c# - LINQ to Entities does not recognize the method 'Int32 IndexOf(System.String, System.StringComparison)' method -

Pygame memory leak with transform.flip -