【问题标题】:Set ajax request in joomla using mootools使用 mootools 在 joomla 中设置 ajax 请求
【发布时间】:2009-09-16 05:56:55
【问题描述】:

我在 joomla 中使用 mootools 处理 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 的完整代码??

提前致谢

【问题讨论】:

    标签: ajax joomla mootools


    【解决方案1】:

    只需将 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 如果你想从服务器端做一些事情以及响应。

    【讨论】:

      【解决方案2】:

      这应该可行:

      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();
      

      【讨论】:

        【解决方案3】:

        也许:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2017-08-05
          • 2014-02-08
          • 2013-04-24
          • 2013-07-06
          • 1970-01-01
          • 2012-02-06
          • 1970-01-01
          相关资源
          最近更新 更多