0

I have a problem with Symfony JsonResponse Component that I used in my app.

JsonResponse always return status code 200.

return new JsonResponse([], JsonResponse::HTTP_BAD_REQUEST);

and jquery ajax

$.ajax({
        type: 'DELETE',
        url: BASE_URL +'/api/cart',
        data: {id: id},
        dataType: 'json',
        success: function (response) {
            waitResponse.resolve(response);
        },
        error: function (error, a, b) {
            waitResponse.reject(error);
        }
    })

Response always evaluate to error with msg "parseerror", but status code is 200. If I remove dataType: 'json', then is always in success. Does anybody know how to fix this problem.

Thanks

1 Answer 1

0

I guess when sending response from the controller you are not sending the second parameter, by default JsonResponse send 200.

send parameter accordingly

$data = null, $status = 200, $headers = array()

check this file more details: Symfony\Component\HttpFoundation\JsonResponse;

official doc JsonResponse

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

1 Comment

I already define response code. It's JsonResponse:HTTP_BAD_REQUEST, which is code 400. So, it must return that code. In symfony app works that way

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.