Ajax replace text with image

后端 未结 2 531
心在旅途
心在旅途 2021-01-26 04:17

I have put together the following mootools script

 window.addEvent(\'domready\', function() {
    var shouts = \"timed.php\";
    var log = $(\'log_res\');
    f         


        
相关标签:
2条回答
  • 2021-01-26 04:25

    Can you not do something like this:

    function updateData (url, target)
    {
      var target = $(target);
      target.innerHTML = 'Please wait...';
    
      //and the rest of the function
    }
    
    0 讨论(0)
  • 2021-01-26 04:39

    With MooTools 1.2, this works as requested:

    function updateData (url, target)
    {
      var target = $(target);
      target.empty().addClass('ajax-loading');
      target.innerHTML = "Loading...";
      new Request({
        url: url, 
        method: 'get',
        onComplete: function(responseText) {
          target.removeClass('ajax-loading');
          target.innerHTML = responseText;
        }
      }).send();
    }
    

    Since you are no fun and use MooTools 1.1, I must dig a little... Actually, I got it working using nearly the same setup as you have (notice I use target instead of log, which was defined outside of the scope of this function):

    function updateData (url, target)
    {
      var target = $(target);
      target.empty().addClass('ajax-loading');
      target.innerHTML = "Loading...";
      new Ajax(url, {
        method: 'get',
        update: target,
        onComplete: function() {
          target.removeClass('ajax-loading');
        }
      }).request();
    }
    
    0 讨论(0)
提交回复
热议问题