是否有可能有類似於以下的路由器實現?主幹表單提交路由
var Router = Backbone.Router.extend({
routes: {
'' : 'search',
'*querystring' : 'results'
},
search: function() {
// load search view
},
results: function(querystring) {
// load search view
// make ajax request using querystring
}
});
搜索視圖有一個表單提交應該去結果視圖將解析的URL查詢時,提交一個Ajax請求,然後顯示響應。
顯然,這樣的事情會更有意義
'results?*querystring' : 'results'
但我不能讓我的形式提交URL該格式。
當我的表單動作爲<form action="index.html/results">
時,我得到http://localhost:8000/index.html/results?c=foo&a=bar
作爲我的URL。
這是接近的,但我真的需要http://localhost:8000/index.html#/results?c=foo&a=bar
,當我嘗試用<form action="index.html#/results">
做到這一點給了我http://localhost:8000/index.html?c=foo&a=bar#/results
這不是我想要的:(
這就是爲什麼我寧願只是沒有形式和行動而不是有如果存在的話可以將分析查詢的路線。
讀好,謝謝。希望有人瞭解一些這一點,並能幫助我。
看來你的表單提交和頁面刷新獲得。你可以嘗試阻止表單提交? – abs