简体   繁体   中英

Express hanging in Chrome post AJAX delete

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);

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM