我正在创建win 8应用程序,用于访问Web服务并在html页面上显示数据。
PAGE1.html访问来自Web服务的数据。第一次打开PAGE1时,可以从Web服务中正确检索数据,然后从PAGE1上的按钮单击事件打开下一页PAGE2.html,该事件调用window.location("PAGE2.html
。但是当我导航回PAGE1.html时,此PAGE1.html会打开但不会显示更新的数据。
PAGE1.html的PAGE1.js代码:在页面的onload函数上正确地从Web服务获取数据。
ready: function (element, options)
{
var textDisp= document.querySelector("#text"); //text is DIV id to display data
textDisp.innerText = "PAGE2";
document.querySelector("#myButton").onclick = function (args) {
WinJS.Navigation.navigate("/pages/page2/page2.html");
};
WinJS.xhr({
type: "GET",
url: "http://MyWebserice",
headers: { "Content-type": "application/json" },
}).then(function complete(request) {
var resdata = request.responseText;
textDisp.innerText = resdata;
}, function error(er) {
var err = er.statusText;
});
}
通过Web服务将数据正确提交到数据库;这是PAGE2.html的PAGE2.js的代码:
document.querySelector("#Submit").onclick = function (args) {
WinJS.xhr({
type: "POST",
url: "http://InsertData?username=" + un + "&password=" + pass + "",
headers: { "Content-type": "application/json" },
}).then(function complete(request) {
WinJS.Navigation.navigate("/pages/PAGE1/PAGE1.html");
}, function error(er) {
var err = er.statusText;
});
}
但是成功添加数据后,PAGE1没有显示数据库的刷新数据,我在WinJS.xhr中调用WinJS.Navigation.navigate("/pages/PAGE1/PAGE1.html")
然后转到PAGE1.html。