Skip to content

Instantly share code, notes, and snippets.

@patridge
Created February 20, 2012 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patridge/1869572 to your computer and use it in GitHub Desktop.
Save patridge/1869572 to your computer and use it in GitHub Desktop.
namespace YourNamespace.Controllers {
using System.Web.Mvc;
using System.Web.SessionState;
using System;
[SessionState(SessionStateBehavior.ReadOnly)]
public class AjaxParallelController : Controller {
public JsonResult GetWait(int i = -1) {
System.Threading.Thread.Sleep(5000);
return Json(new { id = i, type = "parallel", ts = DateTime.Now.Ticks }, JsonRequestBehavior.AllowGet);
}
}
public class AjaxSerialController : Controller {
public JsonResult GetWait(int i = -1) {
System.Threading.Thread.Sleep(5000);
return Json(new { id = i, type = "serial", ts = DateTime.Now.Ticks }, JsonRequestBehavior.AllowGet);
}
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script>
$(function() {
var log = function (data) {
console.log(data.type + "[" + data.i + "]: " + data.ts);
};
for (i = 1; i <= 3; i++) {
$.ajax("/AjaxParallel/GetWait/?i=" + i, {
ifModified: false,
cache: false
}).done(function(data) {
log(data);
});
}
for (i = 1; i <= 3; i++) {
$.ajax("/AjaxSerial/GetWait/?i=" + i, {
ifModified: false,
cache: false
}).done(function(data) {
log(data);
});
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment