Javascript 如何在onsenui中的多个ons模板页面中保留json对象?
这里我在ajax中填充json对象。在navigator页面中,它保留所有json对象。但是当我切换到另一个模板(page2.html)时,它不会保留json对象。 我需要在其他ons模板页面中填充userid,acc_nbr(代码中提到) 有什么帮助吗?Javascript 如何在onsenui中的多个ons模板页面中保留json对象?,javascript,jquery,ajax,json,onsen-ui,Javascript,Jquery,Ajax,Json,Onsen Ui,这里我在ajax中填充json对象。在navigator页面中,它保留所有json对象。但是当我切换到另一个模板(page2.html)时,它不会保留json对象。 我需要在其他ons模板页面中填充userid,acc_nbr(代码中提到) 有什么帮助吗? 这是我的密码 <script> $(document).ready(function(){ $.ajax({ type: "GET", url: "Controller?token=
这是我的密码
<script>
$(document).ready(function(){
$.ajax({
type: "GET",
url: "Controller?token=123",
dataType: 'json',
success: function(data){
$('#userid').html(data.userid);
$('#acc_nbr').html(data.accountnbr);
},
error:function(){
alert("Sorry!");
}
});
});
</script>
$(文档).ready(函数(){
$.ajax({
键入:“获取”,
url:“控制器?令牌=123”,
数据类型:“json”,
成功:功能(数据){
$('#userid').html(data.userid);
$('acc_nbr').html(data.accountnbr);
},
错误:函数(){
警惕(“对不起!”);
}
});
});
index.html
<ons-navigator animation="slide" var="app.navi">
<ons-page>
/*/ content /*/
<div id="userid"></div>
</ons-page>
</ons-navigator>
<ons-template id="page2.html">
<ons-page>
/*/ content /*/
<div id="acc_nbr"></div>
</ons-page>
</ons-template>
/*/内容/*/
/*/内容/*/
尝试将此添加到您的
部分
$(document.body).on("pageinit","#page2.html", function() {
// call that same ajax function
}
例如,我说过like userid。对于填充多个元素,它不起作用