2009-11-16 5 views
0

jQuery - paramètre ajax succès Je veux savoir comment donner une méthode d'objet (fonction), le paramètre de réussite, à la fonction ajax (désolé pour mon anglais)jQuery - paramètre Ajax en fonction de l'objet

permet dis-je déjà mis mon ajax.setup avec tout ce que j'ai besoin d'appeler un php sur le serveur.

function myClass(id) 
{ 
    this.id = id; 

    this.showValues=function(xml) 
    { 
    alert(this.id); // to prove we r in the right object 
    alert(typeof(xml)); // to prove we got the xml  
    }; 

    this.retrieveValues=function() 
    { 
    // wont call the method, this is just text, like writing sucess:"hello" 
    $.ajax({success: this.id+'.showValues'}); 


    // calls the method but this.id is undefined (xml is received tho) 
    $.ajax({success: this.showValues}); 


    // wont call the method 
    $.ajax({success: new Function(this.id+'.showValues')}); 


    // calls the method with the right id but xml is undefined 
    $.ajax({success: new Function(this.id+'.showValues()')}); 


    // js error - "xml not defined" 
    $.ajax({success: new Function(this.id+'.showValues(xml)')}); 


    // of course, next line works, but i dont wanna define the function here 
    $.ajax({success: function() { alert(this.id); alert(typeof(xml)); } });  

    }; 

} 


// even declaring the object as global, so the class has a chance to call a method using the var name 
// wich is this.id+'.retrieveValues' ==> object1.retrieveValues 
var object1; 

function Main() // main =d 
{ 
    object1 = new myClass('object1'); 
    object1.retrieveValues(); 

} 

encore une fois, désolé pour mon mauvais anglais .. = apprentissage encore d j'espère que quelqu'un peut me aider, merci

Répondre

1

trouvé à l'aide de la fonction api aide < _ < je manquais le « xml » paramètre

$.ajax({success: new Function("xml",this.id+'.showValues(xml)')}); 

nouvelle fonction ("xml", this.id + 'showValues ​​(xml)') est comme dire

fonction

(xml) {object1.showValues ​​(xml); }

grâce à dedoz. pas de problème. = D

Questions connexes