AJAX response error: net::ERR_EMPTY_RESPONSE

后端 未结 1 410
刺人心
刺人心 2021-01-16 17:48

CODE:

FRONT-END

$(document).ready(function(){
        $(\'.delete-post\').on(\'click\', function(){
            var id = $(this).dat         


        
1条回答
  •  时光取名叫无心
    2021-01-16 18:48

    The response you're getting is actually correct. Per the docs, Firebase returns a 200 status code and an empty response. net::ERR_EMPTY_RESPONSE is exactly that. What you should do is check for both null and a 200 status code in the response; if true, you can safely assume that the post was deleted.

    My personal opinion is that Firebase should really consider returning something more substantial than nothing and a generic, catch-all status code. I'd prefer something like 204 No Content, or 410 Gone. But, alas.

    Side note: this conditional will never return anything if the post doesn't belong to the author — your API should still return something (an error, probably in this case) even if your conditional doesn't match. Like:

    if (firebase.auth().currentUser.uid.toString() == author) { 
        // your code
    } else {
        res.status(401).send("User does not have permission to complete the operation.")
    }
    

    0 讨论(0)
提交回复
热议问题