使用mootools在joomla中设置ajax请求

时间:2009-09-16 05:56:55

标签: ajax joomla mootools

我在使用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

提前致谢

3 个答案:

答案 0 :(得分:2)

只需将onComplete添加到params对象,无需单独添加事件。另外,你可以使用this.response.text。它可以看起来更紧凑 - 取决于你的偏好。如果您不打算重用该对象,只需直接调用它,不要将其分配给变量:

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

如果您对响应文本执行某些操作,则可能需要删除update:bit。如果您需要评估响应(如javascript),请使用evalResponse:true而不是eval(this.response.text);.也很方便 - evalScripts:true | false如果你想从服务器端做一些事情以及响应。

答案 1 :(得分: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();

答案 2 :(得分:0)

也许:

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