現在,我試圖做的是用html代碼塊替換頭版上的標籤。眼下,網頁主要有:目前在Zend上使用jquery.ajax over .load的問題
<label id="replace"></label>
JS的有:
$(document).ready(function(){
$("#replace").load('/test');
});
了Zend類的功能有:
public function indexAction(){
$this->_helper->layout()->disableLayout();
$this->_view->message = "This is from TestController index";
}
終於index.phtml模板只需有:
<?php echo $this->message;?>
Right現在,我想要改變代碼,以便不用相同的消息替換該標籤,而是使用POST來獲取參數,執行某些操作(例如,轉到數據庫並拖動某個東西用POST參數取出)然後返回消息。
我試過編輯JS,使其看起來像:
$.post('/test', {param : "test_param"},
function(data) {$("#replace").html(data);});
或
$.ajax({
type: 'POST',
url: '/test',
data: "{param:test_param}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {$("#replace").html(data);}
});
和既不工作。我退後一步,試圖複製.load功能,並執行:
$.ajax({
url: '/test',
success: function(data) {
$('#replace').html(data);
alert('Load was performed.');
}
});
而且它也不起作用。
任何人有關於如何去做這個的提示?
我已經改變了一下代碼,以便我可以看到是否有任何彈出錯誤。我在該行上添加了:「error:function(msg){alert('Error with'replace:'.msg);}」在ajax調用中,Firebug報告錯誤:「在屬性列表後面缺少」}。它看起來像我正確關閉我的parens,所以我不知道那裏發生了什麼。 – Matthew 2010-02-12 19:39:16
成功函數和錯誤函數 – thetaiko 2010-02-12 19:40:27
之間缺少逗號也在'alert('錯誤發生在#replace:'.msg'之前] msg之前它應該是一個'+' – 2010-02-12 19:47:46