交火|Twig:在 ajax 调用后更新数据



>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
                }
            })
        }
    });
})

控制器:

public function updateDataAction(Request $request)
{

    $amount = //db call
    return ??
}

我有点卡在这个代码上。我有一个页面,我在其中显示一些数据(金额(,上面有一个过滤器,用户可以在其中操作金额。使用过滤器时,如何使用新的过滤数据更改 amount.low?我被困在我的控制器中应该返回什么,以及我的javascript的成功是什么。

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

use SymfonyComponentHttpFoundationJsonResponse;
// ...
public function updateDataAction(Request $request)
{

    $amount = //db call
    return new JsonResponse(array('amount' => $amount));
}

最新更新