views:

74

answers:

3

I have an ASPX page that I am using to write JSON. It works great in Firefox and Chrome, but when I try and use it in IE 8 it gives me an "The XML page cannot be displayed" error instead of allowing jQuery to load the JSON being written by the response.

Any ideas?

Here is what my code looks like:

   protected override void OnLoad(EventArgs e)
    {
        Response.Clear();
        Response.ClearHeaders();
        Response.ContentType = "application/json";
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Write(string.Format("[ {{ \"Foo\": \"{0}\", \"bar\": \"{1}\" }} ]", "Foo Content", "Bar Content"));
        Response.End();
    }
A: 

Can you post the jQuery you are using? The problem's likely to be there, as there are some differences in the way IE and Firefox handle Javascript and AJAX requests.

From that error, it sounds like IE might be trying to load the JSON as a webpage, instead of making an AJAX request.

minimalis
A: 

what if you get rid of the [ ]'s in the json string? that doesn't look necessary

also, you can use JSON serializer that is built right into .net, and it will definitely be ie8 compatible.

System.Web.Script.Serialization.JavaScriptSerializer

http://blogs.msdn.com/b/rakkimk/archive/2009/01/30/asp-net-json-serialization-and-deserialization.aspx

Sonic Soul
A: 

I ended up "fixing" the problem by not specifying a Content Type. Not sure why it didn't work with the context type as noted above. I've used it for other things without a problem.

Jereme