Set ajax request in joomla using mootools

假如想象 提交于 2019-12-24 12:07:45

问题


I am having a prob for ajax request in joomla using mootools.

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

My prob is that, is there any to set onComplete event of the ajax request. i have set it as below on above code but nothing happen.

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

Can you please provide full code of how to use ajax using mootools 1.1 ??

Thanks in advance


回答1:


just add the onComplete to the params object, no need to add the event seaprately. also, you can use this.response.text. it can all look a bit more compacted - depends on your preference. if you don't plan on reusing the object, just call it direct and don't assign it to a variable either:

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

if you do something with the response text, you may want to remove the update: bit. if you need to evaluate the response (as javascript), use evalResponse: true instead of eval(this.response.text);. also handy - evalScripts: true|false if you want to do something from the server side along with the response.




回答2:


This should work:

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:


maybe:

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


来源:https://stackoverflow.com/questions/1431179/set-ajax-request-in-joomla-using-mootools

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!