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>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<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.id + "]: " + 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