2009-09-16 33 views
1

我對使用mootools的joomla中的ajax請求有一個概率。使用mootools在joomla中設置ajax請求

var url = '<?php echo JURI::base();?>index.php?option=com_test&task=getselectmode&selectedid='+$('parent_question').value; 

    var params ={method: 'post',update:'test'}; 
    var myAjax = new Ajax(url, params); 
myAjax.request(); 

我的問題是,是否有任何設置ajax請求的onComplete事件。 我已經在上面的代碼中將它設置爲如下,但沒有發生。

onComplete: function(response) { alert('Response: ' + response); } 

請問您能否提供完整的代碼,介紹如何使用mootools 1.1來使用ajax?

在此先感謝

回答

2

只需添加的onComplete到params對象,無需seaprately添加事件。另外,你可以使用this.response.text。它可以看起來更緊湊 - 取決於你的喜好。如果你不重用對象的計劃,只是把它直接和不將其分配給一個變量之一:

new Ajax(url, { 
    method: "get", 
    update: $("someelement"), 
    onComplete: function() { 
     alert(this.response.text); 
    } 
}).request(); 

,如果你做一些與響應文本,您可能需要刪除的更新:位。如果您需要評估響應(如JavaScript),請使用evalResponse:true而不是eval(this.response.text);.也很方便 - evalScripts:true | false如果您想從服務器端與響應一起執行某些操作。

0

這應該工作:

var ajaxObj = new Ajax ('index.php?option=com_yourcomponent&view=yourview&format=raw', { 
    method: "get" 
}); 

ajaxObj.addEvent('onComplete', function (data) { 
    // data is the response text 
    // use as desired 
}); 

// this initiates the call 
ajaxObj.request(); 
0

也許:

var a = new Ajax(url, { 
     method: 'post', 
     data: { parfoto: foto }, 
     onComplete: function(response){ 
      .......... 
     } 
}).request();