public
Created

  • Download Gist
AjaxParallelController.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
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);
}
}
}
testajax.html
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
<!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>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.