0

I'm making ajax request to the generic handler Handler.ashx, which forwards this request to a REST service in another domain. Handler is used to achieve cross-domain call. I get the data in Firefox & Chrome. But not in Safari on Windows 7(Ver. 5.1.7)

$.ajax({
         url: 'Handler.ashx',
         type: 'GET',
         contentType: 'application/json; charset=utf-8',
         dataType: 'json',
         async: false,
         timeout: 20000,
         data: data,
         success: function (received_data) {
             // Process data
         },
         error: function (err) {
             console.log(err);
         }
});

My Handler.ashx code:

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(new Uri("http://xxx.xxx.xx.xxx/MyWebService/Service.svc/DownloadFile"));
    req.ContentType = "application/json; charset=utf-8";
    req.Timeout = 60000;

    using (WebResponse resp = req.GetResponse()) 
    { 
        StreamReader reader = new StreamReader(resp.GetResponseStream());
        string responceFromService = reader.ReadToEnd();
        context.Response.ContentType = "application/json; charset=utf-8";
        context.Response.Write(responceFromService);
    }

The error I get is:

NETWORK_ERR: XMLHttpRequest Exception 101

mike44
  • 802
  • 5
  • 15
  • 36
  • http://stackoverflow.com/questions/6965942/network-err-xmlhttprequest-exception-101 – CBroe May 02 '13 at 12:48
  • http://stackoverflow.com/questions/15913170/phantom-js-synchronous-ajax-request-network-err-xmlhttprequest-exception-101 – Rachel Gallen May 02 '13 at 12:58
  • I am also getting the same error like "Error: NETWORK_ERR: XMLHttpRequest Exception 101", I have also seen above links still not get any solution can anyone tell me what exactly problem with the safari browser. – Hardik Patel Sep 20 '13 at 15:14

3 Answers3

1

Try setting the async parameter to true

$.ajax({
    url: 'Handler.ashx',
    type: 'GET',
    async: true,
});
Alex
  • 9,911
  • 5
  • 33
  • 52
  • The thing is that I can not go further until I get the data & process it. I'm building blocks with the help of that data. – mike44 May 02 '13 at 12:38
  • So just code your logic by calling relevant functions inside the complete callback function, there is no valable reason to use ajax async false, none im aware of. – A. Wolff May 02 '13 at 12:41
  • @A. Wolff: I am also having the same problem, my ajax call is working in all browsers except safari. can you please explain me what exactly fault it. – Hardik Patel Sep 20 '13 at 15:16
1

From everything I can find surfing around on the web, and my own testing, Safari times out synchronous ajax calls after 10 seconds. And, there is no way to get around it. (I've tried.) This is not a bug. It is simply Apple's way of hinting to you that if your call can't reliably return in 10 seconds, you shouldn't be using a synchronous call. In fact, you probably shouldn't ever use a synchronous call because there is no way to know if your call will return in 10 seconds. You need to refactor your code to have whatever would happen after the ajax call, happen via the callback routine, and not in-line.

user2037235
  • 86
  • 1
  • 2
0

My ajax call were failing only in Safari. What worked for me was preventing the default button click behavior using event.preventDefault()

Akhil Mohandas
  • 202
  • 1
  • 10