$ .ajax does not work properly on IE6

Basically, I have something like this:

$.ajax({
    type: "GET",
    url: "my_url",
            cache: true,                
            success: function(data) {
              /* code here */
            },
        dataType: 'json'
}); 

This code works in all tested browsers (IE7 / 8, chrome, safari, firefox), but the success function is not called in IE6.

I used Fiddler to find out what is happening in the HTTP requests and everything looks fine, I get the expected result as an HTTP response, but success does not seem to be called in IE6, the same goes for onerror.

Any thoughts?

+3
source share
4 answers

Are you sure this is not just a cache? Delete the browser cache and check again.

"", POST ( GET- ajax ie6).

+1

complete success. , , , ...

$.ajax({
  type: "GET",
  cache: true,
  complete: function(xhr) {
    if(xhr.status != 200) {
      throw "Error!";
      return;
    }

    var data = xhr.responseText;
  }
});
+2

, . jQuery AJAX IE ASP.NET ( ashx). , , ( POST, GET, ).

ASP.NET, IE6. (IE6 SP2 , IIS 7.5). , IE6?

. , - IE6 "SetCacheability" ashx.cs, "" , . , , , "no-cache" ?

index.html

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>AJAX GET test</title>
    </head>
    <body>
        <input type="button" id="test" value="Send" />
        <script type="text/javascript" src="jquery-1.3.2.min.js"></script>
        <script type="text/javascript">
            $("#test").click(function () {
                $.ajax({
                    url: "Api.ashx?param=one",
                    cache: true,
                    type: "GET",
                    dataType: "json",
                    success: function (data) {
                        alert("Success, result = " + data.result);
                    },
                    error: function (request, status, err) {
                        alert("Error");
                    }
                });
            });
        </script>
    </body>
</html>

file Api.ashx

<%@ WebHandler Language="C#" CodeBehind="Api.ashx.cs" Class="AjaxTest.Api" %>

file Api.ashx.cs

using System.Diagnostics;
using System.Text;
using System.Web;

namespace AjaxTest
{
    public class Api : IHttpHandler
    {
        public bool IsReusable { get { return true; } }
        public void ProcessRequest(HttpContext context)
        {
            var param = context.Request["param"]; // this flushes the request
            Trace.WriteLine("Request: \"" + context.Request.RawUrl + "\", param: \"" + param + "\"", "** Debug");
            context.Response.StatusCode = 200;
            context.Response.ContentType = "application/json";
            context.Response.ContentEncoding = Encoding.UTF8;
            context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            context.Response.Write("{\"result\":\"" + param + "\"}");
        }
    }
}
+1

, ?

$.ajax({
        type: "GET",
        url: "my_url",
        cache: true,
        success: function(data) {
              /* code here */
            },
        error: function(data) {
              alert(data.responseText);
            },
        dataType: 'json'});

http://docs.jquery.com/Ajax/jQuery.ajax#options

0

Source: https://habr.com/ru/post/1726453/


All Articles