iPhone 5 Safari - setting sessionStorage blocks execution of the rest of the code

iPhone 5 Safari - setting sessionStorage blocks execution of the rest of the code

It seems I encountered an issue with setting sessionStorage by iPhone 5 Safari browser (latest IOS version) - in desktop browsers all works flawless.

I have this simple code validating a login form with ajax:

  1. <script>
  2. $(document).bind('pageinit', function() {                 
  3. $("button#submit").on('click', function() {                      
  4. if ($("#username").val() === "" || $("#password").val() === "") {
  5. $("div#response").html("Please enter both username and password");
  6. } else {                 
  7. $.ajax({
  8. type: 'POST',
  9. url: 'php/login.php',
  10. data: $("#loginForm :input").serializeArray(),
  11. success: function(data) {
  12. if (data === 'success') {                                                        
  13. window.location = 'start.html';                        
  14. } else {                                    
  15. $("div#response").html(data);
  16. };
  17. }                           
  18. });
  19. }             
  20. $("#loginForm").on('submit', function() {
  21. return false;
  22. });                    
  23. });                 
  24. });      
  25. </script>

I'm trying to set the sessionStorage like this:


  1. sessionStorage.password = $("#password").val();
but I don't know where to put this line without blocking execution of the further code. The obvious thing would be to put it inside the click event (to create session after a click) but putting it in the beginning blocks the ajax (I just get message from PHP file). When I put it lower outside the ajax or outside the click function or outside pageinit function, the sessionStorage is not set at all.

What is wrong? Do I set the sessionStorage correctly? All seems to work fine on desktop browsers.