I have a relatively simple example of an MVC page that is using jQuery to make a POST to get some JSON data and then just show a success/failure message when it is done. The code works perfectly fine in the other browsers but in IE7/8 it seems to fail 4/5 times.
Here is the MVC View Page:
<asp:Content runat="server" ContentPlaceHolderID="MainContent">
<p id="message"></p>
</asp:Content>
<asp:Content runat="server" ContentPlaceHolderID="HeadContent">
<script type="text/javascript" src="<%= Url.Content("~/Scripts/jquery-1.4.1.min.js") %>"></script>
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
type:"POST",
url: "<%= Url.Action("GetData") %>",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data){
$("#message").html("success");
},
error: function(XMLHttpRequest, textStatus, errorThrown){
$("#message").html("error: " + textStatus + "<br/>exception:" + errorThrown);
}
});
});
</script>
</asp:Content>
The controller is pretty simple as well:
[HttpPost]
public ActionResult GetData()
{
IList<string> people = new List<string>
{
"A",
"B",
"C",
"D",
"E"
};
return Json(people);
}
It seems to fail in IE 4 out of every 5 times roughly. I put some logging code in the controller and it calls the controller action every time, even when it fails. Does anyone see anything that I am doing wrong here?
When it hits my error handler function the textStatus is just set to "error" and errorThrown is undefined.