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:
- <script>
- $(document).bind('pageinit', function() {
- $("button#submit").on('click', function() {
- if ($("#username").val() === "" || $("#password").val() === "") {
- $("div#response").html("Please enter both username and password");
- } else {
- $.ajax({
- type: 'POST',
- url: 'php/login.php',
- data: $("#loginForm :input").serializeArray(),
- success: function(data) {
- if (data === 'success') {
- window.location = 'start.html';
- } else {
- $("div#response").html(data);
- };
- }
- });
- }
- $("#loginForm").on('submit', function() {
- return false;
- });
- });
- });
- </script>
I'm trying to set the sessionStorage like this:
- 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.