Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> jQuery + ajax
zomb
post
Post #1





Grupa: Zarejestrowani
Postów: 68
Pomógł: 1
Dołączył: 7.06.2009
Skąd: Sanok

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


Witam,
zacząłem bawić się jQuery. Znalazłem w sieci skrypt sprawdzający pola:
http://roshanbh.com.np/2008/04/check-usern...php-jquery.html

chciałem go trochę przerobić:

  1. <script language="javascript">
  2. $(document).ready(function()
  3. {
  4. $("#username").blur(function()
  5. {
  6. //remove all the class add the messagebox classes and start fading
  7. $("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");
  8. //check the username exists or not from ajax
  9. $.post("user_availability.php?co=acc",{ user_name:$(this).val() } ,function(data)
  10. {
  11. if(data=='no') //if username not avaiable
  12. {
  13. $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
  14. {
  15. //add message and change the class of the box and start fading
  16. $(this).html('This User name Already exists').addClass('messageboxerror').fadeTo(900,1);
  17. });
  18. }
  19. else
  20. {
  21. $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
  22. {
  23. //add message and change the class of the box and start fading
  24. $(this).html('Username available to register').addClass('messageboxok').fadeTo(900,1);
  25. });
  26. }
  27.  
  28. });
  29.  
  30. });
  31. });


główna "przeróbka" to:
  1. $.post("user_availability.php?co=acc",{ user_name:$(this).val() } ,function(data)


oraz:
  1. switch ($_GET['co']) {
  2. case 'acc':
  3. $existing_users=array('roshan','mike','jason');
  4. //value got from the get metho
  5. $user_name=$_POST['user_name'];
  6. //checking weather user exists or not in $existing_users array
  7. if (in_array($user_name, $existing_users))
  8. {
  9. //user name is not availble
  10. echo "no";
  11. }
  12. else
  13. {
  14. //user name is available
  15. echo "yes";
  16. }
  17. break;
  18.  
  19. }


  1. <div >
  2. User Name : <input name="username" type="text" id="username" value="" maxlength="15" />
  3. <span id="msgbox" style="display:none"></span>
  4. </div>



czyli dodanie switcha, niestety po tym co zrobiłem skrypt przestał działać, switcha dodałem w celu "zautomatyzowania" skryptu (żebym później nie musiał tworzyć osobnych plików .js i .php do sprawdzania). Wiem że problem jest w przekazywaniu zmiennej czyli $user_name=$_POST['user_name'];, po prostu nie czyta tego co się wpisało tylko cały czas pisze że można zarejestrować pomimo tego że wpisze się mike ect.
Proszę o pomoc.

Ten post edytował zomb 23.12.2010, 19:15:31
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 24.12.2025 - 16:31