Search Results

Search found 2 results on 1 pages for 'acoder'.

Page 1/1 | 1 

  • MooTools event listener disappears after element.innerHTML is changed

    - by acoder
    Hi everyone, I am trying to achieve this task using MooTools. Description: I attached an event listener to "myButton" link. A click on this link initiates an AJAX request and updates "myDiv" content based on the response text. During this request a POST variable is being sent to "button.php", but it's not used at the moment.. (i wish to use it later) OK, as a result, "myDiv" gets exactly the same link with the same ID (myButton) + a random number, so that we could see that each click generates a new number. The problem: After the first click on "myButton", "myDiv" updates correctly, showing a random number. When I click "myButton" for the second time (this time in newly updated div), the div does not refresh anymore. Please note that I need "myButton" to be inside "myDiv", and "myDiv" must be updated (refreshed) after each click without having to refresh the entire page. Can somebody show me how to achieve this task based on this simplified code example? index.html <html> <head> <script type="text/javascript" src="mootools-1.2.4-core-nc.js"></script> <script> window.addEvent('domready', function() { $('myButton').addEvent('click', function(e) { e.stop(); var myRequest = new Request({ method: 'post', url: 'button.php', data: { action : 'test' }, onRequest: function() { $('myDiv').innerHTML = '<img src="images/loading.gif" />'; }, onComplete: function(response) { $('myDiv').innerHTML = response; } }); myRequest.send(); $('myButton').removeEvent('click'); }); }); </script> </head> <body> <div id="myDiv"> <a id="myButton" href="#">Button</a> </div> </body> </html> button.php <a id="myButton" href="#">Button</a> clicked <?php echo rand(1,100); ?>

    Read the article

  • MooTools request fails

    - by acoder
    Hi everyone, I am trying to achieve this task using MooTools. Description: I have three buttons. Two buttons outside myDiv and one button inside myDiv. A click on any of these buttons initiates an AJAX request (passing button variable to "button.php") and updates myDiv content based on the response text. So, after update, myDiv shows Button3 link + a message showing which button has been clicked. The problem: Everything seems to work fine but after several clicks, it happens that myDiv shows loader.gif image and stops. After this, if I wait a few moments, the browser sometimes stops working (gets blocked). I noticed this problem with IE6. Does anyone know what does this problem mean and how it can be avoided? index.html <html> <head> <script type="text/javascript" src="mootools/mootools-1.2.4-core-nc.js"></script> <script type="text/javascript" src="mootools/mootools-1.2.4.4-more.js"></script> <script type="text/javascript"> window.addEvent('domready', function() { $("myPage").addEvent("click:relay(a)", function(e) { e.stop(); var myRequest = new Request({ method: 'post', url: 'button.php', data: { button : this.get('id'), test : 'test' }, onRequest: function() { $('myDiv').innerHTML = '<img src="images/loader.gif" />'; }, onComplete: function(response) { $('myDiv').innerHTML = response; } }); myRequest.send(); }); }); </script> </head> <body> <div id="myPage"> <a href="#" id="button1">Button1</a> <a href="#" id="button2">Button2</a> <div id="myDiv"> <a href="#" id="button3">Button3</a> </div> </div> </body> </html> button.php <a href="#" id="button3"Button3</a> <br><br> <?php echo 'You clicked ['.$_REQUEST['button'].']'; ?>

    Read the article

1