question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JQuery trying to parse a 204 No content response

See original GitHub issue

When I do an Ajax request and the server return an 204 No content response JQuery (v1.11.3) try to parse the content and I get this error: JQMIGRATE: jQuery.parseJSON requires a valid JSON string (json = ""). I don’t know if it’s the cause but the response I got from the server does have:

Content-Length: 4
Content-Type: application/json

It’s an error from the server but HTTP spec say that a 204 code mean that there’s no content so JQuery mustn’t try to parse a 204 response.

Here’s how I was used JQuery:

$.ajax({
    url: 'myurl',                                                           
    type: 'DELETE',
    headers: {'Accept':'application/json'},                                              
});                                                                                   

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:19 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
Hunsucommented, May 28, 2015

The HTTP spec say that an HTTP 204 doesn’t have a body so jQuery must not try to parse it. But if it’s a feature I can live with it. It just jQuery doesn’t respect the HTTP spec, that the problem.

0reactions
timmywilcommented, May 28, 2015

In this case, I think it was actually helpful that jQuery tried to parse the response and failed because it uncovered a server issue. We’ll leave this as-is.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to handle a 204 response in jquery ajax? - Stack Overflow
This object has a property for the http status code of the result. Save this answer. Show activity on this post. I tested...
Read more >
ajax 204 NoContent with no JSON in the response, will fire the ...
After a ton of research, ajax blows up on a 204 if the body is empty, because it gets Content-Type: application/json so it...
Read more >
13654 (Ajax response with status code 204 triggers fail() on ...
Since 204 is a success with No Content, a 204 response should always trigger a success unless there is any content, which would...
Read more >
http 204 no content - how to return a value? - Web Dev
The idea to to send a form to the server and have the server respond with a 204 response so that the current...
Read more >
What are HTTP Status Codes ? - GeeksforGeeks
204 No Content Response came without no entity-body; 205 Reset Content The browser should clear the form used for this transaction for ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found