Framework7 导航不工作
Framework7 navigation not working
我有这个-app.js:
var myApp = new Framework7({
closeByOutsideClick : true,
init: false
});
var $$ = Dom7;
// Add view
var mainView = myApp.addView('.view-main');
function avvia(info) {
$.ajax({
type: "POST",
contentType: "application/json",
//data: {info : info},
data : JSON.stringify(info),
timeout: 6000,
url: "http://localhost:8180/api/",
success: function(data){
urlRedirect = data.urlRedirect;
//window.location.href = urlRedirect;
mainView.router.loadPage(urlRedirect);
},
beforeSend: function() {
myApp.showPreloader('Loading...');
},
complete: function(data) {
myApp.hidePreloader();
},
error: function (xhr, status, error) {
// executed if something went wrong during call
myApp.alert(error, ' Error');
//if (xhr.status > 0) alert('got error: ' + status); // status 0 - when load is interrupted
}
});
}
myApp.init();
在我的 ajax 调用之后,我想将页面重定向到一个新页面,如果成功,该页面将作为数据字段返回。
我的问题是 Framework7 导航 mainView.router.loadPage(urlRedirect)
不工作,而标准 window.location.href = urlRedirect;
工作正常。我该如何解决?
您的 url 重定向是否仅返回 Ajax 页面所需的 HTML 还是返回完整的 Framework7 应用程序所需的 html?我的意思是,如果您返回的不仅仅是 Ajax 页面的结构,路由器将不知道如何处理它,并且可能看起来什么都不做。
如果你调用loadPage(url),url应该只包含,例如:
<div class="page" data-page="about">
... About page content goes here
</div>
此外,导航栏标记,header/footer,等等,但没有别的。
我有这个-app.js:
var myApp = new Framework7({
closeByOutsideClick : true,
init: false
});
var $$ = Dom7;
// Add view
var mainView = myApp.addView('.view-main');
function avvia(info) {
$.ajax({
type: "POST",
contentType: "application/json",
//data: {info : info},
data : JSON.stringify(info),
timeout: 6000,
url: "http://localhost:8180/api/",
success: function(data){
urlRedirect = data.urlRedirect;
//window.location.href = urlRedirect;
mainView.router.loadPage(urlRedirect);
},
beforeSend: function() {
myApp.showPreloader('Loading...');
},
complete: function(data) {
myApp.hidePreloader();
},
error: function (xhr, status, error) {
// executed if something went wrong during call
myApp.alert(error, ' Error');
//if (xhr.status > 0) alert('got error: ' + status); // status 0 - when load is interrupted
}
});
}
myApp.init();
在我的 ajax 调用之后,我想将页面重定向到一个新页面,如果成功,该页面将作为数据字段返回。
我的问题是 Framework7 导航 mainView.router.loadPage(urlRedirect)
不工作,而标准 window.location.href = urlRedirect;
工作正常。我该如何解决?
您的 url 重定向是否仅返回 Ajax 页面所需的 HTML 还是返回完整的 Framework7 应用程序所需的 html?我的意思是,如果您返回的不仅仅是 Ajax 页面的结构,路由器将不知道如何处理它,并且可能看起来什么都不做。
如果你调用loadPage(url),url应该只包含,例如:
<div class="page" data-page="about">
... About page content goes here
</div>
此外,导航栏标记,header/footer,等等,但没有别的。