Why is the callback function receiving a XMLHttpRequest object instead of a JSON object?
<%@ Page language='C#' %>
<%
if (Request.RequestType == "POST") {
System.Threading.Thread.Sleep(1000);
int c;
if (Session["c"] == null)
c = 1;
else
c = (int)Session["c"] + 1;
Session["c"] = c;
Response.ContentType = "application/json";
Response.Write("{\"mike\": " + c.ToString() + "}");
Response.End();
}
%>
<html>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
function callback(data,s) {
if (s=="success")
$("h1").text(data.responseText);
else
$("h1").text(s);
setTimeout(updateUI,0);
}
function updateUI () {
$.ajax({ url: "timer.aspx",
contentType: "application/json; charset=utf-8",
dataType: "json",
timeout: 5000,
type: "POST",
data: "{}",
complete: callback});
}
$(function() {
setTimeout(updateUI,0);
});
</script>
<body>
<h1/>
</body>
</html>