Witam.
Mam pewien problem podczas pisania skryptu odpowiadającego za dynamiczne tworzenie katalogu na serwerze.

CSS + Wyświetlanie listy katalogów
  1. <style type="text/css" media="all">
  2. #create_catalog {float:left;margin:0;padding:5px 10px;width:auto;height:auto;border:1px dotted #393939;background:#123456;color:#FFFFFF;}
  3. #create_catalog:hover {float:left;margin:0;padding:5px 10px;width:auto;height:auto;border:1px dotted #393939;background:#654321;color:#FFFFFF;}
  4. #catalog_name {float:left;margin:0;padding:5px 10px;width:150px;height:auto;border:1px dotted #393939;background:#FFFFFF;color:#FF0000;display:none;}
  5. #create {float:left;margin:0;padding:5px 10px;width:auto;height:auto;border:1px dotted #393939;background:#123456;color:#FFFFFF;display:none;}
  6. #create:hover {float:left;margin:0;padding:5px 10px;width:auto;height:auto;border:1px dotted #393939;background:#654321;color:#FFFFFF;display:none;}
  7. #status {float:left;margin:0;padding:5px 10px;width:auto;height:auto;border:1px dotted #0090FF;background:#FFFFFF;color:#0090FF;display:none;display:block;}
  8. <?php
  9. $directory = 'upload/';
  10. $dir = opendir($directory);
  11. $file_list = '<ul>';
  12. while($file_name = readdir($dir)) {
  13. if(($file_name != '.') && ($file_name != '..')) {
  14. $file_list .= '<li>'.$file_name.'';
  15. }
  16. }
  17. $file_list .= '</ul>';
  18. closedir($dir);
  19. echo '
  20. Pliki w '.$directory.':'.$file_list.'';
  21. ?>



  1. $(document).ready(function() {
  2. $('#create_catalog').click(function(){
  3. setInterval(function() {
  4. $("#catalog_name").fadeIn();
  5. }, 100);
  6. setInterval(function() {
  7. $("#create").fadeIn();
  8. }, 300);
  9. });
  10. $('#create').click(function(){
  11. var pattern = '/^[A-Za-z0-9_ \-]+$/i';
  12. var folder = $('#catalog_name').val();
  13. if(!pattern.test($(folder).val())) {
  14. alert("Niedozwolone znaki !");
  15. } else {
  16. //if ($this.find('input[name=folder]').val()) {
  17. $.ajax({
  18. type: "POST",
  19. url: "create.php",
  20. data: "folder=" + folder,
  21. success: function() {
  22. setInterval(function() {
  23. $("#catalog_name").fadeOut();
  24. }, 100);
  25. setInterval(function() {
  26. $("#create").fadeOut();
  27. }, 300);
  28. var contents = ['Tworzę katalog...', 'Katalog został pomyślnie utworzony :)'];
  29. var current = 0;
  30. setInterval(function() {
  31. document.getElementById('status').innerHTML = contents[current++];
  32. }, 500);
  33. },
  34. error: function(){
  35. alert("error !");
  36. }
  37. });
  38. }
  39. });
  40. });


  1. <div id="create_catalog">Utwórz katalog</div>
  2. <div id="status"></div>
  3. <form method="POST">
  4. <input type="text" value="" name="folder" id="catalog_name" />
  5. <button id="create">Utwórz</button>
  6. </form>


Może mi ktoś powiedzieć dlaczego skrypt nie wyświetla komunikatów, tylko od razu odświeża stronę ?
Tak samo nie waliduje formularza "/^[A-Za-z0-9_ \-]+$/i"

Za każdą pomoc będę bardzo wdzięczny.
Pozdrawiam.



EDIT !
  1. $(document).ready(function() {
  2. $('#create_catalog').click(function(){
  3. setInterval(function() {
  4. $("#catalog_name").fadeIn();
  5. }, 100);
  6. setInterval(function() {
  7. $("#create").fadeIn();
  8. }, 300);
  9. });
  10. $('#create').click(function(){
  11. var pattern = /^[A-Za-z0-9_ \-]+$/i;
  12. var folder_name = $('#catalog_name').val();
  13. var folder = $('#catalog_name');
  14. if(!pattern.test($(folder).val())) {
  15. alert("Niedozwolone znaki lub brak nazwy katalogu !");
  16. } else {
  17. $.ajax({
  18. type: "POST",
  19. url: "create.php",
  20. data: "folder_name=" + folder_name,
  21. success: function() {
  22. //if ($this.find('input[name=folder]').val()) {
  23. setInterval(function() {
  24. $("#catalog_name").fadeOut();
  25. }, 100);
  26. setInterval(function() {
  27. $("#create").fadeOut();
  28. }, 300);
  29. var contents = ['Tworzę katalog...', 'Katalog został pomyślnie utworzony :)'];
  30. var current = 0;
  31. setInterval(function() {
  32. document.getElementById('status').innerHTML = contents[current++];
  33. }, 500);
  34. setInterval(function() {
  35. parent.location='<?php $PHP_SELF; ?>';
  36. }, 10000);
  37. //} else {
  38. // alert("Nie podales nazwy !");
  39. //}
  40. //return false;
  41. },
  42. error: function(){
  43. alert("error !");
  44. }
  45. });
  46. }
  47. });
  48. });


Działa alert gdy są niedozwolone znaki lub brak nazwy, ale nadal nie działają komunikaty w divie o id='status', które mają się pojawiać gdy utworzono katalog, a dopiero po tym odświeżyć stronę...



DO ZAMKNIĘCIA, JUŻ SOBIE PORADZIŁEM ! smile.gif
Dzięki Wam za MEGA zainteresowanie ;]