javascript - Parsing json stored in localstorage - Error NS_ERROR_DOM_BAD_URI -


i've read lot of posts around without success. i'm developing simple set/get localstorage of json stringified, in following link.

unfortunately, got error:

request failed: error, ns_error_dom_bad_uri: access restricted uri denied

this sniplet i'm using (just tests):

var id_expert = "1"; var testjson = "js/testjson.js";  $.getjson(testjson)           .done(function( data ) {  //////// store ///////////                     window.localstorage.setitem("id_expert_selected", id_expert);                     var list = 'questions_'+id_expert;     window.localstorage.setitem(list,json.stringify(data));    ////////// retrieve //////////////                                     var id_exp = window.localstorage.getitem('id_expert_selected');     var list_answ = window.localstorage.getitem('questions_'+id_expert);     var test = json.parse(list_answ) || {};   $.getjson( test )   .done(function( data ) { <---------- i'm not able got it. ... bla bla bla... 

in sniplet, store/retrive json string, without parsing success. i'm sure json because when use without localstorage, got parsing.

any clue?

edit:

i got same result using this:

$.getjson( list_answ )       .done(function( data ) { <---------- i'm not able got it.     ... bla bla bla... 

i tried changing flag in firefox config (some security stuff), error still there. on real android device, in debug, read kind of error description:

file:///storage/emulated/0/android/data/com.intel.html5tools.apppreview/cac…/previews/myapp/1/%7b%22username%22:%22myusername%22,%22pwd%22:%22mypwd%22%7d net::err_file_not_found

thanks megaappbear solved:

//// store json /////

window.localstorage.setitem("id_expert_selected", id_expert);                     var list = 'questions_'+id_expert;     window.localstorage.setitem(list,json.stringify(data));  

//// retrieve json /////

var id_expert = window.localstorage.getitem('id_expert_selected');     var list_data = window.localstorage.getitem('questions_'+id_expert),       def = $.deferred();      if (!list_data) {         def = $.getjson('js/test.json', function(data) {             /// save data using localstorage.setitem         });     }else{         list_data = json.parse(list_data);         def.resolve();     }      def.done(function() { var expert_name = document.getelementbyid('expert_name');                 expert_name.textcontent = list_data.nameexpert; ..... , on ....... 

i not sure you're trying here.

var test = json.parse(list_answ) || {}; // returns object

and

$.getjson( test ); // expects uri


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -