我有一个包含图像的页面。在每个图像中,都有一个 onClick 事件和一个 id,用于查看该配方的详细信息。单击时,它通过 AJAX 转到控制器中的操作,从而使用 Twig 生成新视图。问题是它不会重新加载(不是提交按钮),当我将响应分配给html时,新页面开头的菜单不起作用。而且,此外,不会更改URL(仅当我制作那个棘手的window.history.pushState时,并且在刷新页面之前无法将历史记录回溯)
断续器
<img src="{{recipe.image}}" onclick="showDetail()" id={{recipe.id}}>
断续器
function showDetail() {
var detailId = $(event.target).attr('id');
$.ajax({
type: "post",
url: "showDetail",
dataType: "html",
data: {id:detailId},
success: function(res){
// $("html").html(res); // this one makes menus don't work
},
error: function(jqXHR, textStatus, errorThrown){ $("#respRecipe").html(textStatus + ' ' + jqXHR.status + ' ' + errorThrown); }
});
控制器
public function showDetailAction($params) {
$model = new DetailModel;
$recipeData = $model->recipeDataDB($params["id"]);
View::renderTwig('Detail/detail.html', array('recipeData'=>$recipeData[0],
'ingredientsData'=>$recipeData[1], 'commentsData'=>$recipeData[2]));
}
routes.json (我可以更改这个以接受参数而不需要AJAX吗?
"showDetail": {
"controller": "DetailController",
"action": "showDetail"
},
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^([a-zA-Z0-9\-\_\/]*)$ index.php?p=$1
</IfModule>
我不知道我是否可以,但图像内隐藏了一个提交按钮...主要问题是刷新页面,URL和工作菜单。
提前致谢。
回首忆惘然
弑天下
一只斗牛犬
幕布斯6054654
相关分类