Kaskus

Tech

nanyacoyAvatar border
TS
nanyacoy
[HELP] Ajax PrototypeJS (Need Your Solution)
gan tolong,
ane lagi belajar pake prototype js..
ada masalah waktu request ajax nya..
ane punya variable yg nilainya di dapat dari database, dan di set nya pake javascript..

pertama ane coba gini :
PHP Code:
var MyClass = Class.create({
     
    
ajaxFile: 'MyClass.php',
    
total0,

    
getAjaxUrl: function() {
       return 
Functions.ajaxPath + '/' + this.ajaxFile;
    
},

    
fooBar: function() {
        new 
Ajax.Request(this.getAjaxUrl(), {
            
method: 'get',
            
parameters: 'get=total',
            
onSuccess: function(response) {
                
this.total response.responseText// misal return value nya 13
                
alert(this.total); // hasilnya bener 13
            
}
        }
        
alert(this.total); // tapi kalo disini total masih 0, belum berubah
    
}
}) 

untuk case code di atas kenapa bisa begitu yah gan ?? emoticon-Bingung (S)

terus kedua ane coba buat local variable di method itu
PHP Code:
var MyClass = Class.create({
     
    
ajaxFile: 'MyClass.php',

    
getAjaxUrl: function() {
       return 
Functions.ajaxPath + '/' + this.ajaxFile;
    
},

    
fooBar: function() {
        var 
foo 0;
        new 
Ajax.Request(this.getAjaxUrl(), {
            
method: 'get',
            
parameters: 'get=total',
            
onSuccess: function(response) {
                
foo response.responseText// misal return value nya 13
                
alert(foo); // hasilnya bener, dapet 13
            
}
        }
        
alert(foo); // tapi kalo disini total masih 0, belum berubah
    
}
}) 

dari code yg kedua ini, hasilnya masih sama kaya contoh code pertama..

mohon solusinya dong mastah kenapa bisa begitu..
dan kalo gak keberatan, tolong dijelaskan why emoticon-Big Grin


Thx emoticon-Smilie
0
688
0
GuestAvatar border
Komentar yang asik ya
GuestAvatar border
Komentar yang asik ya
Komunitas Pilihan