0
所有我能找到的文檔中有你定義的實際功能是這樣如何使用prototypejs ajax onSuccess事件調用現有的已定義的javascript函數?
new Ajax.Request('/your/url', {
onSuccess: function(response) {
// Handle the response content...
}
});
ajax的構造函數中調用但我的代碼拋出一個錯誤,說「遺漏的類型錯誤:未定義是不是一個函數」 這裏是我的試圖調用現有函數pullComments()的代碼。
function addComment(){
// Stringify json
var commentStr = $('#commentBox').value;
var JSONObj = { "dealID" : dealID,
"username" : "default",
"comment" : commentStr };
JSONObj = JSON.stringify(JSONObj);
var JSONComment = encodeURIComponent(JSONObj);
new Ajax.request("php/savecomment",
{
method: 'POST',
parameters: "comment=" + JSONComment,
onSuccess: pullComments()
});
}
function pullComments(){
// Grab the comments for the deal
var xmlhttp
****
從onSuccess末尾刪除'()':pullComments()' –