2017-04-05 114 views
0

我有這個在我的-app.js:Framework7導航不工作

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;工作正常。我該如何解決這個問題?

回答

0

您的urlRedirect僅返回Ajax頁面所需的HTML,還是返回完整的Framework7應用程序的HTML?我的意思是,如果您返回的不僅僅是Ajax頁面的結構,路由器將不知道如何處理它,並且可能看起來什麼都不做。

如果調用loadPage(URL),該URL應該只包含,例如:

<div class="page" data-page="about"> 
    ... About page content goes here 
</div> 

此外,導航欄標記,頁眉/頁腳等,但沒有別的。