1

Index.html.twig

{% if amount.low != 0 %}
    <p class="amount">{{ amount.low|round(0, 'floor') }}</p>
{% endif %}

Javascript:

$(document).ready(function () {
    $("#Filter1").change(function() {
        var input = $(this).val();

        if(inputCPU.length >= 1) {
            var data = {input: input};
            $.ajax({
                type: "POST",
                url: ROOT_URL + "default/update/data",
                dataType: 'json',
                timeout: 3000,
                success: function(response){
                    $(".amount").html(response.result); ???
                        console.log(response.result);

                },
                error: function() {
                    alert('Error with showing the filter.') //debug reasons
                }
            })
        }
    });
})

Controller:

public function updateDataAction(Request $request)
{


    $amount = //db call

    return ??
}

I'm a bit stuck on this code. I've a page where I show some data (amount), above there is a filter where users can manipulate the amount. How can I change the amount.low with the new filtered data when a filter is used? I'm stuck on what I should return in my controller and what the success whould be in my javascript.

1 Answer 1

1

http://symfony.com/doc/current/components/http_foundation.html#creating-a-json-response

use Symfony\Component\HttpFoundation\JsonResponse;

// ...

public function updateDataAction(Request $request)
{


    $amount = //db call

    return new JsonResponse(array('amount' => $amount));

}
Sign up to request clarification or add additional context in comments.

2 Comments

For some reason I'm not geting any results back? It's like I'm not going into the updateDataAction methode. You have any idea what the problem might be?
You could try to request that route/action straight from the browser.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.