Problem with ajax response

0

I'm doing a project in Symfony and when I send the data by ajax the answer I generate with json_encode() gives me error

This is my ajax code

$.ajax ({
    data: {"id": id_category, "type": "add_row_interno"},
    type: "POST",
    dataType: "json",
    url: "{{ path('acme_smart_action') }}",
    success: function (rescue_data,status) {
        alert(JSON.stringify(rescue_data));
    },
    error:function (rescue_data) {
        alert(JSON.stringify(rescue_data));
    }
});

answer function

public function showRowProducts($id_service)
{
    $result["result"] = "result";
    return new Response(json_encode($result));
}

and I get the following in error

{"readyState":4,"responseText":"{\"result\":\"result\"}","status":200,"statusText":"OK"}
    
asked by tomas lagos 14.07.2016 в 17:40
source

1 answer

1

By default it is already formatted in JSON

Change this:

alert(JSON.stringify(rescue_data));

Because of this:

console.log(rescue_data);

Obs: Check it in the "console" panel of your browser and do not use alerts for these things.

    
answered by 14.07.2016 / 22:56
source