Greettins.
I am trying to persist some data that i get in the web page using an xhr request.
The problem it's seems to be that no data is being recorded to the phone as in the next launch you can not retrieve the info.
- I am using the "Nokia Web Developer Environment 1.2.0" currently to developt the app and testing with the preview emulator that comes within.
- Using the widget.preferences.setItem(key,data) and widget.preferences.setItem(data) as the doc says
I paste the javascript along with html code to see what i am doing more precisely
HTML CODE:
Code:
<input type="button" onclick="getJSON();" value="Get JSON"/><br/>
<input type="button" onclick="getIt();" value="retrieve data from pref"/>
JAVASCRIPT CODE:
Code:
function getJSON()
{
var xhr;
xhr = new XMLHttpRequest();
xhr.open("GET","http://www.geonames.org/postalCodeLookupJSON?postalcode=10504&country=US", true);
xhr.onreadystatechange = function(){
if (xhr.readyState == 4) {
if (xhr.status == 200) {
document.getElementById('test').innerHTML= "<b>"+ xhr.responseText + "</b><br/>";;
widget.preferences.setItem("REG001",xhr.responseText);
}
else {
document.getElementById('test').innerHTML= "Error code " + xhr.status;
}
}
}
xhr.send(null);
}
function getIt ()
{
document.getElementById('test').innerHTML = document.getElementById('test').innerHTML + "<br/>" + widget.preferences.getItem("REG001");
}
Well thanks for advance.
Grettins!.
Víc
P.D: This wasn't actually tested on a real phone, just on the emulator. BUT it obviously must work, or don't?