IE9 JSON Data “do you want to open or save this file”

后端 未结 5 553
温柔的废话
温柔的废话 2020-11-28 08:57

Started testing my jQuery applications with IE9. Looks like I may be in for some trouble here. I noticed that when I return JSON data back to the Javascript methods I always

5条回答
  •  我在风中等你
    2020-11-28 09:35

    I also faced this problem yesterday with WebAPI which returned a list of URLs (of asynchronously uploaded files).

    Just set content type to "text/html" instead of default "application/json; charset=UTF-8" of WebAPI services. I got response as a JSON string and then used $.parseJSON to convert it to JSON object.

    public async Task Upload()
    {
      // ...
      var response = Request.CreateResponse(HttpStatusCode.OK, files);
      response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
      return response;
    }
    
    // result is an iframe's body content that received response.
    $.each($.parseJSON(result.html()), function (i, item)
    {
      console.log(item.Url);
    });
    

提交回复
热议问题