Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [JavaScript]Wywołanie metody w innej metodzie
borpaw
post
Post #1





Grupa: Zarejestrowani
Postów: 439
Pomógł: 0
Dołączył: 3.06.2010

Ostrzeżenie: (50%)
XXX--


Mam pytanie jak moge w takim układzie jak poniżej wywołać metode this.func() albo odczytać zmienną this.name questionmark.gifquestionmark.gif

  1. function klasa( name )
  2. {
  3. this.name = name;
  4.  
  5. this.func = function() { alert("test") };
  6.  
  7. this.action = function()
  8. {
  9. $.ajax({
  10. type:"POST",
  11. url: "plik.php",
  12. cache:false,
  13. success:function(rsponse)
  14. {
  15. alert(this.name); //udefined
  16. this.func(); //undefined
  17. }
  18. });
  19. };
  20.  
  21. }
Go to the top of the page
+Quote Post
kamil4u
post
Post #2





Grupa: Zarejestrowani
Postów: 2 350
Pomógł: 512
Dołączył: 4.01.2009
Skąd: Wrocław / Świdnica

Ostrzeżenie: (0%)
-----


[JAVASCRIPT] pobierz, plaintext
  1. function klasa( name )
  2. {
  3. this.name = name;
  4.  
  5. this.func = function() { alert("test") };
  6.  
  7. this.action = function()
  8. {
  9. var that = this;
  10. $.ajax({
  11. type:"POST",
  12. url: "plik.php",
  13. cache:false,
  14. success:function(rsponse)
  15. {
  16. alert(that.name); //udefined
  17. that.func(); //undefined
  18. }
  19. });
  20. };
  21.  
  22. }
[JAVASCRIPT] pobierz, plaintext


--------------------
Go to the top of the page
+Quote Post
wookieb
post
Post #3





Grupa: Moderatorzy
Postów: 8 989
Pomógł: 1550
Dołączył: 8.08.2008
Skąd: Słupsk/Gdańsk




[JAVASCRIPT] pobierz, plaintext
  1. function klasa( name )
  2. {
  3. this.name = name;
  4.  
  5. this.func = function() { alert("test") };
  6.  
  7. this.action = function()
  8. {
  9. $.ajax({
  10. type:"POST",
  11. url: "plik.php",
  12. context: this, // watch this
  13. cache:false,
  14. success:function(rsponse)
  15. {
  16. alert(this.name); //udefined
  17. this.func(); //undefined
  18. }
  19. });
  20. };
  21.  
  22. }
[JAVASCRIPT] pobierz, plaintext

// watch this


--------------------
Go to the top of the page
+Quote Post
borpaw
post
Post #4





Grupa: Zarejestrowani
Postów: 439
Pomógł: 0
Dołączył: 3.06.2010

Ostrzeżenie: (50%)
XXX--


dzieki, o to chodziło
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.08.2025 - 05:11