2

When issuing a same-origin AJAX delete via jQuery, subsequent calls to the server via the same client are hanging. I've excerpted the problem below. Please advise if something is malformed as this would seem like such a strange bug.

Using Express 3.5.1, jQuery 1.11.0, and Chrome 33.x.

To replicate:

  1. Create directory with code below and install Express dependency
  2. node main.js
  3. Visit localhost:5000 in Chrome 33
  4. Click on simulated deletion link
  5. Wait for a moment, and refresh

In the Network region, Chrome will handle the DELETE request ok, but the subsequent server call will stay as "pending". I have tried both HTML and JSON dataTypes and responses.

main.js:

// Dependencies
var http = require('http'),
    express = require('express');

// Basic app
var app = express();

// Logging (for debugging), and parsing dependencies
app.use(express.logger());
app.use(express.json());
app.use(express.urlencoded());
app.use(express.cookieParser());
app.use(express.methodOverride());

// Simple home page
app.get("/", function(req, res) {
  var head   = "<head><script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.0/jquery.min.js'></script></head>",
      body   = "<a id='link' style='text-decoration:underline;cursor:pointer;'>Click here to simulate delete</a>, wait a second, then try refreshing.",
      params = {
        url  : "/item/5",
        type : "DELETE"
      }
      ajax = "<script>$(function() { $('#link').click(function() { $.ajax(" + JSON.stringify(params) + "); }); });</script>"

  res.send("<html>" + head + "<body>" + body + ajax + "</body></html>");

});

// Simulated deletion
app.del("/item/:id", function(req, res) {
  res.send(204);
});

// Make the server listen
var server = http.createServer(app).listen(5000);
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • try returning 200 not 204. 204 may be misinterpreted as "no content" so chrome may just be hanging with no content. More explanations here: http://blog.ploeh.dk/2013/04/30/rest-lesson-learned-avoid-204-responses/ – Biba Apr 24 '14 at 23:09
  • @user3564913 I am facing the same problem. Did you find a solution? – Ivan Jan 27 '16 at 12:09
  • @user3574913 I've posted an answer below... – user3564913 Jan 28 '16 at 17:07

1 Answers1

0

This ended up being a non-node-related third-party plugin (I believe it was Sophos, but I may be mistaken). Once the plugin was disabled, everything worked fine.

You can see more information here: https://github.com/strongloop/express/issues/2069