Sunday, 23 October 2022

jQuery/Ajax page redirection is not working in iPhone and Safari

I am trying to redirect one page to another using jQuery/ajax. Here I am using php as server side.

This is how I send data to js:

$url = 'index.php?p=dashboard'; 
// print the message to Ajax:
$messages = array('success'=>true,'pageRedirect'=>$url);      
echo json_encode($messages);

This is how I handle the response in AJAX

var request;
$("#login").on('submit', function(e) {
  e.preventDefault();
        
  if (request) {
    request.abort();
  }

  var $form = $(this);
  var $inputs = $form.find("input, select, button, textarea");
  var serializedData = $form.serialize();

  $inputs.prop("disabled", true);
  
  request = $.ajax({
    url: "user_processing.php",
    type: "post",
    data: serializedData,
    success: function(json) {
      json = jQuery.parseJSON(json)        
      if (json.success) {
        setTimeout(function() {
          $(window).attr('location',json.pageRedirect);
        }, 500);
      } 
    }
  });
  
  request.always(function () {
    $inputs.prop("disabled", false);
  });
});

My problem is, above everything works properly in firefox and chrome, but this redirection is not working in iphone and safari browsers. Hope somebody may help me out.



from jQuery/Ajax page redirection is not working in iPhone and Safari

No comments:

Post a Comment