Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery AJAX functions not working in iOS 5 Safari/iPad

Tags:

jquery

ios

Using the latest version of jQuery 1.6 on iOS 5 safari from an iPad, I'm noticing that all my ajax calls are failing. These same ajax calls work as expected on all other browsers I've tried, and I'm pretty sure they were also working on iOS 4's version of Safari (although I could be wrong). Has anyone else experienced this behavior as well? If so, is there a fix or workaround? Below is a quick example of a simple jQuery AJAX call that is returning an error in iOS 5's Safari. Thanks in advance for any insight!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>
  </head>
  <body>
    <a id="my-link" href="javascript:;">Click Me!</a>
    <script type="text/javascript">
      jQuery(document).ready(function() {
        jQuery("#my-link").bind("click", function() {
          jQuery.get("test.php", function(data) {
            alert(data);
          });
        });
      });
    </script>
  </body>
</html>
like image 537
ajporterfield Avatar asked Oct 30 '11 01:10

ajporterfield


3 Answers

I had a similar issue just now. I had

 $.ajax({
        type: 'post',
        url: 'http://IP../ws',
        data: {1:1},
        dataType: 'json',
        success: function(response) {
            if (lng.Core.toType(callback) === 'function') {
               // setTimeout(callback, 100, response);
                callback(response);
            }
        },
        error: function(xhr, type) {
            console.log('error')
            if (error) {
                setTimeout(error, 100, result);
            }
        }
    });

changed url: 'http://IP../ws', to url: 'ws',

I'm not a jQuery user at all but have to use it for a project so not sure if this is help to you or not but worked for me.

like image 134
Daithi44 Avatar answered Nov 15 '22 20:11

Daithi44


Restart Safari - leave it and kill it from the running tasks.

From other things I have read it is related to security contexts and prevention of cross site scripting attacks, and Safari not getting things quite right when it was previously running on a different network and is now on an new network without it having been stopped between changing networks.

Ran into it myself today, w/ plain HTML/JavaScript/PHP XMLHttpRequest request.

like image 22
prniii Avatar answered Nov 15 '22 20:11

prniii


I had face one issue that jQuery ajax call fail in IPad in Safari browser. Error is you have no permission to access the page / directory. I fix the issue by changing the Ajax async property to true.

 $.ajax({
        type: 'GET',
        url: "".
        async: true,
        cache: true,
        crossDomain: false,
        contentType: "application/json; charset=utf-8",
        dataType: 'json',
        error: function (jqXHR, err) {
            console.log(jqXHR.responseText);
            alert("Error" + jqXHR.responseText);
        },
        success: function (data, status) {

            });
like image 24
Jameel Moideen Avatar answered Nov 15 '22 21:11

Jameel Moideen