0

Currently I'm working through some tutorials on using web tokens, and I got the back end working (ie when authentication is successful it sends back a signed token). However, I'm having trouble seeing how to actually store it locally in storage, I keep getting "out of memory exception".

    form(id='creds' role='form' method='post')
        .form-group
            label.sr-only(for='email') Username:
            input.form-control(id='email' type='text', name='email', placeholder='Email')
        .form-group
            label.sr-only(for='password') Password:
            input.form-control(id='password' type='password', name='password', placeholder='Password')
        .text-center
            button.btn.btn-primary.btn-block(type='submit') Submit
            p  
    script.
        $(document).ready(function() {
            $('#creds').on('submit', function() {
                var creds = {
                    email: $('#email').val(),
                    password: $('#password').val()
                }
                var jqxhr = $.post('/login', creds, function(data) {
                    window.sessionStorage.token = data.token;
                    alert('success!');
                });
                jqxhr.fail(function() {
                    $('#password').val('');
                    alert('failure!');
                });
            });
        });

What am I doing wrong?

Thanks

errorline1
  • 350
  • 1
  • 6
  • 18
  • You are getting the web token, but not being able to store in sessionStorage right? – shikhar bansal Nov 06 '15 at 18:50
  • Not even, I just get out of memory exception, none of the alerts work. Btw, edit that input retrieval is "val()" instead of "text()", typo on my part. – errorline1 Nov 06 '15 at 19:00

2 Answers2

0

Looks like your trying to set it as a property on the sessionStorage object, rather than using the utility methods.

sessionStorage.setItem(key, value);
sessionStorage.getItem(key);

https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage

Taplar
  • 24,788
  • 4
  • 22
  • 35
  • Roger that, changed. However I still get the "out of memory exception", seemingly it's coming from the .post – errorline1 Nov 06 '15 at 19:10
0

The answer is how the submit is handled in post methods. See this post

uncaught exception: out of memory in Ajax Process

Community
  • 1
  • 1
errorline1
  • 350
  • 1
  • 6
  • 18