Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
96
rated 0 times [  97] [ 1]  / answers: 1 / hits: 20488  / 11 Years ago, sat, july 20, 2013, 12:00:00

I'm having some trouble getting a local storage variable to store the proper value. The jist of it is I want to display the contents of the local variable, then if the user clicks, it pulls the data from an .xml file, saving it to a local variable.



Problem is, that it doesn't save to the local variable properly. I have tried a variety of syntax to get it to work and I am out of ideas.



Test site for it is located at http://web.engr.oregonstate.edu/~todtm/assignment2.html



Script Code:



function startAjax()
{
$(#clickme).text(Calling server);
$.ajax(
{
url: xmlpage.xml,
success: callbackFunction,
error: errorFunction
});
}

function callbackFunction(data, info)
{
var titles = $(data).find(title);
if (titles && titles.length)
{
$(#results).text(result: + titles.text());
localStorage.setItem('titles', #results.text());
}
else
errorFunction(data, No titles);
}

function errorFunction(data, info)
{
$(#clickme).text(error occurred: + info);
}

$(document).ready(function ()
{
$(#results).text(localStorage.getItem('titles'));
});

More From » jquery

 Answers
29

you have a syntax error, need to get



localStorage.setItem('titles', $('#results').text());


or



localStorage.setItem('titles', titles.text());

[#76863] Thursday, July 18, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kiyam

Total Points: 448
Total Questions: 96
Total Answers: 92

Location: Philippines
Member since Sat, Jul 11, 2020
4 Years ago
;