这里我在ajax中填充json对象。在导航页面中,它保留了所有的json对象。但是当我切换到另一个模板(page2.html)时,它不会保留 json 对象。 我需要在其他 ons-template 页面中填充 userid、acc_nbr(代码中提到的)。
对此有什么帮助吗?
这是我的代码。
<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>
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>
最佳答案
尝试将其添加到您的 <script>
部分
$(document.body).on("pageinit","#page2.html", function() {
// call that same ajax function
}
关于javascript - 如何在onsenui中的多个ons-template页面中保留json对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26377268/