Search code examples
phpjqueryhtmlsafarimobile-safari

Latest Safari not working with location.href in jQuery


Does anyone have an answer for this problem?

Basically I have exhausted all possible answers from other questions on here and I am driven to open a new call for help!

The problem... I have a log in page that has a log in form. The submit button has a jQuery click function attached. The click function has an ajax call to some php checking a DB. Upon success the location is then re-directed to another page. Now this works on every browser except the latest version of safari! I have also tried different versions of jQuery. It is very frustrating. See code below for your take.

Any suggestions/solutions would be greatly appreciated.

Thanks in advance.

------------Update----------

Anyone who comes across this issue, the solution I came up with was to re-write the solution in AngularJS. I would suggest you do the same!

Hope this helps.

------------HTML--------------

<form id="loginFRM" style="text-align: center;">
      <input style="margin:20px; padding-left:5px;" id="username" name="username" type="text" placeholder="Username...">
      <br>
      <input style="margin:20px; padding-left:5px;" id="password" name="password" type="password" placeholder="Password...">
      <br>
      <input style="margin:20px; background-color: white; border: none; padding:10px; padding-left:30px; 
             padding-right:30px;" id="loginBtn" type="submit" value="Login" onclick="return false;">
    </form>

----------jQuery----------

$(document).ready(function(){
  $('#loginBtn').click(function(){
    var username = $("#username").val(),
            password = $("#password").val();

    if(username != "" && password != ""){
      $.ajax({
        type: "GET",
        url: './server/index.php',
        data: {
          username: username,
          password: password
        },
        success: function(response)
        {
          rowCount = response.ResultSet.RowCount;
          if(rowCount > 0){
              window.setTimeout(function(){ location.href = "index.html"; },0);
              return false;
          }
          else{
            alert('Incorrect details');
          }
        }
      });
    }else{
      alert('Incorrect details');
    }

    return false;

  });
});

Solution

  • Anyone who comes across this issue, the solution I came up with was to re-write the solution in AngularJS. I would suggest you do the same!