ugrás a tartalomhoz

Ajax.Request egy osztályon belül

aramisz · 2008. Júl. 31. (Cs), 13.05
Szeretném segítségeteket kérni abban, hogy az alábbi kódot hogy kell módosítanom ahhoz, hogy a func2 metódusban lévő Ajax.Request-ben hogy tudom átvenni a már kiértékelt változókat.
  1. var jsClass = Class.create();  
  2. jsClass.prototype = {  
  3.     initialize: function(p1, p2, p3){  
  4.         this.p1 = p1;  
  5.     this.p2 = p2;  
  6.     this.p3 = p3;  
  7.     this.func1();  
  8.     this.func2();  
  9.     },  
  10.       
  11.     func1: function(){  
  12.         this.p4 = = this.p1 + this.p2 + this.p3;  
  13.         $('div_result').innerHTML = this.p4;  
  14.     }  
  15.       
  16.     func2: function(){  
  17.         var a1 = new Ajax.Request('ajax.php', { method:'post',  
  18.             parameters: 'mode=p1&p1='+this.p1,  
  19.             onSuccess: function(transport){  
  20.               var p5 = transport.responseText;  
  21.               alert(p5>this.p4?true:false);  
  22.               // alert-ben a this.p4 értéke undefined, hogy tudnám áthozni ide a számított eredményt,   
  23.               // hogy tudjak vele értékelni?  
  24.             }  
  25.           });  
  26.     }  
  27. }  
 
1

bind a barátod

toxin · 2008. Júl. 31. (Cs), 13.34
http://www.prototypejs.org/api/function/bind

üdv Csaba
2

bind lesz a barátom

aramisz · 2008. Júl. 31. (Cs), 14.41
Egy egyszerű példát tudnál írni, hogy megértsem, vagy esetleg kiegészítenéd a kódomat, mert sajnos nem jöttem rá a használatára.
3

re

toxin · 2008. Júl. 31. (Cs), 14.59
  1. <html>  
  2.     <head>  
  3.         <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />  
  4.         <title>Ajax - bind</title>  
  5.         <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.2/prototype.js"></script>  
  6.         <script type="text/javascript">  
  7.             var jsClass = Class.create();  
  8.             jsClass.prototype = {  
  9.                 initialize: function(p1, p2, p3){  
  10.                     this.p1 = p1;  
  11.                     this.p2 = p2;  
  12.                     this.p3 = p3;  
  13.                     this.func1();  
  14.                     this.func2();  
  15.                 },  
  16.                   
  17.                 func1: function(){  
  18.                     thisthis.p4 = this.p1 + this.p2 + this.p3;  
  19.                     $('div_result').innerHTML = this.p4;  
  20.                 },  
  21.                   
  22.                 func2: function(){  
  23.                     var a1 = new Ajax.Request('ajax.php', {  
  24.                         method: 'post',  
  25.                         parameters: 'mode=p1&p1=' + this.p1,  
  26.                         onSuccess: function(transport){  
  27.                             var p5 = transport.responseText;  
  28.                             alert(p5 > this.p4 ? true : false);                             
  29.                         }.bind(this)  
  30.                     });  
  31.                 }  
  32.             };  
  33.               
  34.             window.onload = function(){  
  35.                 oFoo = new jsClass(1,2,3)  
  36.             };  
  37.         </script>  
  38.     </head>  
  39.     <body>  
  40.         <div id="div_result"></div>  
  41.     </body>  
  42. </html>  
üdv Csaba

ui: a 18. sorban egy this van : kódszinező
4

bind lett a barátom

aramisz · 2008. Júl. 31. (Cs), 15.50
Köszönöm, igy már teljesen érthető. :)