檢查它...它是可以做到這一點。
首先在服務器端:
if ($_GET['action'] == "educational_resources"){
if(isset($_GET['kind'])){
header("Content-Type: text/xml");
header("Cache-Control: no-cache");
header("Pragma: no-cache");
$smarty->compile_check = true;
$smarty->force_compile = 1;
$kind = $_GET['kind'];
$reply = true;
if($kind == "get_classroom_resources"){
$class_id = $_SESSION['user']['class_id'];
$classData = $curriculum->get_class_data($class_id);
$units = $curriculum->get_units();
$chapters = $curriculum->get_modules();
$smarty->assignGlobal('classData', $classData);
$smarty->assignGlobal('units', $units);
$smarty->assignGlobal('chapters', $chapters);
$smarty->display('classroom.tpl');
}
}
if(!isset($reply)){
$file[1] = "educational_resources.tpl";
$file[2] = "footer.tpl";
}
}
設置我的行動處理器包含了所有我的Ajax請求處理程序了。如果「$ _GET [‘種’]設置我知道這是一個Ajax請求。因此,如果$種設置,設置頭配置,並告訴智者強制編譯(這是確保了返回什麼解析HTML)。
下使你的TPL文件。
<h1>Period: {$classData.period} - {$classData.description}</h1>
<h4>{$classData.name} - {$classData.city}, {$classData.state}</h4>
<p>The content area below shall povide a convienient way to browse all the curriculum, and provide a detailed view that summarizes the student's performance
as he/she progresses through each chapter.</p>
<ul>
{foreach from=$units name=units key=k item=i}
<li>
Unit {$smarty.foreach.units.iteration} - {$i.title}
<ul>
{foreach from=$chapters name=chapters key=c item=v}
{if $i.id == $v.unit_id}
<li>Chapter {$smarty.foreach.chapters.iteration} - {$v.descriptor}</li>
{/if}
{/foreach}
</ul>
</li>
{/foreach}
</ul>
最後,在jQuery的事件處理程序,使Ajax調用(您想返回的HTML):
$('#classroom').css({'background-image': 'url("./images/classroom.png")', 'margin': '0 .5em 0 0'})
.live('click', function(event){
//window.location="?action=classroom";
$('#stupid_wrapper').css({'width': '106px', 'overflow': 'auto', 'float': 'left', 'margin': '0'});
$('#stupid_table').css({'padding': '1em', 'width': '80px'});
$('#classroom').css({'margin': '0 0 .5em 0', 'width': '80px', 'height': '54px', 'background-image': 'url("./images/classroom_icon.png")'});
$('#project').css({'margin': '0 0 .5em 0', 'width': '80px', 'height': '54px', 'background-image': 'url("./images/project_icon.png")'});
$('#reportcard').css({'width': '80px', 'height': '54px', 'background-image': 'url("./images/reportcard_icon.png")'});
$('.cell').css({'float': 'none'});
var classroomHTML = '<div id="icon_panel"></div>';
$(classroomHTML).appendTo('#content');
$('#icon_panel').css({'float': 'left', 'width': '75%', 'margin': '0 0 0 1em', 'background-color': '#f6f6f6', 'border': '1px solid #cdcdcd', 'padding': '2em', 'border-radius': '1em', '-moz-border-radius': '1em'})
getClassroomResources();
});
function getClassroomResources(){
$.ajax({
type: 'GET',
url: '?action=educational_resources&kind=get_classroom_resources',
dataType: 'html',
beforeSend: function(xhr){
xhr.setRequestHeader("Ajax-Request", "true");
},
success: function(reply){
$('#icon_panel').html(reply);
}
});
return false;
}
感謝IBM爲這個! http://www.ibm.com/developerworks/opensource/library/wa-aj-smarty/index.html?ca=drs-
哦,聽起來像***的痛苦...有時我愛smarty,有時我只是希望它...更聰明..!該死的......謝謝兄弟。 – 2011-05-23 20:27:13
嗯,請記住,這裏的問題並不聰明,但它是serverside(php,smarty)和clientside(html,javascript/jquery)之間的「衝突」。祝你好運! – Nanne 2011-05-23 20:32:04
感謝他......現在轉到別的東西......義務「衝突」管:http://www.youtube.com/watch?v=GqH21LEmfbQ&feature=fvst:P謝謝 – 2011-05-23 22:09:00