0

I'm using Phonegap to build my app,in first page I'm using $.getJSON to load data and I want to use that object in all other pages. How to do this? I tried assigning it to a global variable in a call back method of $.getJSON but I'm getting it as undefined in next page so can any one help me in this. I have my .js file and I'm loading it in all the pages. I'm calling particular function on $(document).ready() of every page. Declared a global variable at top,initializing it in 2nd page function and want to load that variable in next page $(document).ready().

4

1 回答 1

3

你可以做这样的事情,

一个.html

$.getJSON(function(data){
    localStorage.setItem("getJSONData",JSON.stringify(data));
})

B.html

var getJSONData = JSON.parse(localStorage.getItem("getJSONData"));

如果您只想存储当前会话的数据,您可以使用sessionStorage

于 2013-08-23T04:59:11.483 回答