【发布时间】:2014-01-11 07:32:00
【问题描述】:
我有 2 个 ajax 调用(一个用于获取标题内容,一个用于获取图像内容)。两者都以 JSON 格式返回。 要渲染,我有 2 个车把模板。
问题是:仅渲染了一个车把模板(有时会渲染标题,有时会渲染图像)。 网址: http://www.devfolio.info/ankit/index.php
代码: JS文件
function getPhotos(uid){
var dataString = 'action=viewPhotobank&uid=' + uid;
$.ajax({
type:"POST",
url: "/themesAssets/controller/actions.php",
data: dataString,
success: function(msg){
response = JSON.parse(msg);
if(response.statusPhotos == "success"){
if(typeof(afterGetUserphotobank) != 'undefined'){
afterGetUserphotobank();
} else{
var sourcePhotos = $("#images-template").html();
var templatePhotos = Handlebars.compile(sourcePhotos);
$("#content").fadeOut(animationTime, function(){
$("#content").html(templatePhotos(response))
.fadeIn(animationTime);
});
}
}
}
});
}
function getHeaderData(uid){
var dataString = 'action=getHeader&uid=' + uid;
$.ajax({
type:"POST",
url: "/themesAssets/controller/actions.php",
data: dataString,
success: function(msg){
response = JSON.parse(msg);
if(response.statusHeader == "success"){
if(typeof(afterGetSingleImage) != 'undefined'){
afterGetHeaderData();
} else{
var sourceHeader = $("#header-template").html();
var templateHeader = Handlebars.compile(sourceHeader);
$("#header").fadeOut(animationTime, function(){
$("#header").html(templateHeader(response))
.fadeIn(animationTime);
});
}
}
}
});
}
在主页上:
<body>
<div id="header"></div>
<div id="content"></div>
<div id="footer"></div>
<script>
$(document).ready(function(){
getHeaderData(<?= $uid ?>);
getPhotos(<?=$uid?>);
});
</script>
<?php
require_once $rootFolder . '/themes/classy/headerTemplate.php';
require_once $rootFolder . '/themes/classy/imagesTemplate.php';
?>
</body>
<?php
require_once '../../global.php';
require_once $rootFolder . '/classes/portfoliodata.class.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php
$data = new portfolioData();
$data->getViewport();
$data->getCharset();
$data->getCommonCSS();
$data->getCommonJS();
$data->getThemeCSS("classy", "grid");
?>
</head>
<body>
<div id="header"></div>
<div id="content"></div>
<div id="footer"></div>
<?php
require_once $rootFolder . '/themes/classy/headerTemplate.php';
require_once $rootFolder . '/themes/classy/singleImageTemplate.php';
require_once $rootFolder . '/themes/classy/imagesTemplate.php';
?>
<script>
$(document).ready(function(){
getHeaderData(<?= $uid ?>);
getPhotos(<?= $uid ?>);
});
</script>
</body>
</html>
【问题讨论】:
-
您需要发布代码,向我们展示您尝试过的内容,具体失败的地方等。可能会制作一个 JSFiddle 以直观地向我们展示我们可以编辑的内容。
-
类似问题(答案很广泛,但解释了为什么这种情况发生得比我好)stackoverflow.com/questions/19084299/…
-
另外一个相关的情况,这个描述了PHP和HTTP/1.1是如何背后的。 stackoverflow.com/questions/898190/…
标签: jquery handlebars.js