Crossman
Crossman

Reputation: 278

Sending localStorage variables through the jQuery Ajax function without it being in the url

Good day,

I would just like to know if there is a way of sending localStorage variables through the Ajax function without it being in the url. For example:

$.ajax({
    type: "POST",
    url: "../pages/profile.php",
    data: localStorage.email,
    dataType: 'json'
    success: function(result)
    {     
        //document.location.replace('../pages/main.php');
    },
    error: function()
    {
        alert('An Error has occured, please try again.');
    }
});

The return type from the php will be JSON in this case, as needed.

Thanks in advance

Upvotes: 0

Views: 1504

Answers (1)

Jon
Jon

Reputation: 4736

change

data: localStorage.email,

to

data: {email: localStorage.getItem('email')}

So that the data is in proper JSON format, and using (I believe) the correct way to retrieve an item from localStorage.

Upvotes: 1

Related Questions