Jquery $.get against ASP.NET MVC not working in Opera and Firefox
- by codelove
Let me first put the code snippets here. I am just using the ASP.NET MVC project Visual Studio creates out of the box. So I am just putting the snippets I added to it:
Site.master's head section:
<head runat="server">
<title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
<script src="../../Scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
<link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
<script src="../../Scripts/test.js" type="text/javascript"></script>
<script type="text/javascript">$(document).ready(ready);</script>
</head>
Content of test.js:
function ready(){
$.get("/Home/TestAjax", ajaxResponse);
}
function ajaxResponse(data){
alert("got response from server: " + data);
}
Method in HomeController:
public String TestAjax()
{
if (Request.IsAjaxRequest())
{
return "Got ajax request!";
}
else
{
return "Non-ajax request";
}
}
Now the problem I am seeing in Firefox 3.5.30729 (Firebug) is when the ajax request goes out, IIS 7 on the remote box sends Http 302 back, which does the redirect and forces another get request, but it is not asynchronous. Opera also doesn't work so I assume it is the same problem. However, above code works just fine in IE 8, Chrome, and Safari.
On localhost all of the above browsers work as expected including Firefox and Opera -- they all receive "Got ajax request!" as the response from the server.
Anybody have any ideas what's going on here and how to fix it? I am looking for a real solution or at least explanation as to what is going on and why.