Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript]Problem z czatem, jw
miras
post
Post #1





Grupa: Zarejestrowani
Postów: 1 004
Pomógł: 9
Dołączył: 18.01.2011
Skąd: Siedlce

Ostrzeżenie: (30%)
XX---


Witam, problem jest następujący - mam pewien czat, na którym wiadomości wyświetlają się dopiero po podaniu nazwy użytkownika, a ja chciałbym, żeby wiadomości czatu wyświetlały się od razu, tylko jak ktoś będzie chciał napisać wiadomość to będzie musiał podać ten nick.

tutaj jest główny kod js:

http://wklej.org/hash/15b83e7bf12/

wiadomości wyświetlane są w tym divie:

  1. <div id="messages"></div>


według mnie trzeba edytować tą funkcję (próbowałem na wszystkie sposoby, które przyszły mi do głowy)

  1. function chat_msgs_get()
  2. {
  3. chat_tout = setTimeout("chat_msgs_get();", Math.round(1000*chat_timeout));
  4. if (chat_XMLHttp_get.readyState % 4) return;
  5. chat_rand += 1;
  6. chat_XMLHttp_get.open("get", chat_path+"php/msg_get.php?rand="+chat_rand+
  7. "&room="+encodeURIComponent(chat_room)+
  8. "&user="+encodeURIComponent(chat_user)+
  9. "&pass="+encodeURIComponent(chat_pass)+
  10. "&mptr="+chat_mptr);
  11. chat_XMLHttp_get.send(null);
  12. chat_XMLHttp_get.onreadystatechange = function()
  13. {
  14. if(chat_XMLHttp_get.readyState == 4 && chat_XMLHttp_get.status == 200)
  15. {
  16. document.getElementById('log_get').innerHTML = chat_XMLHttp_get.responseText;
  17.  
  18. var data = chat_parse(chat_XMLHttp_get.responseText);
  19. if (data[0] == '-' && chat_user && chat_pass) { chat_api_onload(chat_room, true); return; }
  20. for (var i = 1; i < data.length-1; i++)
  21. {
  22. chat_mptr = Math.max(chat_mptr, data[i]);
  23.  
  24. if (data[i+1] == '+')
  25. {
  26. if (chat_smsg) if (data[i+2] == chat_room) chat_msgs['.'] += '<b>System:</b> user <b>'+chat_msgs_usr(data[i+3], 'black', false)+'</b> enters the room<br />';
  27. chat_usrs[data[i+3]] = new Array(data[i+2], data[i+4], data[i+5], true);
  28. i += 5;
  29. }
  30.  
  31. if (data[i+1] == '-')
  32. {
  33. if (chat_smsg) if (data[i+2] == chat_room) chat_msgs['.'] += '<b>System:</b> user <b>'+chat_msgs_usr(data[i+3], 'black', false)+'</b> leaves the room<br />';
  34. chat_usrs[data[i+3]] = false;
  35. i += 3;
  36. }
  37.  
  38. if (data[i+1] == 's')
  39. {
  40. if (chat_usrs[data[i+2]]) chat_usrs[data[i+2]][3] = data[i+3] == '+';
  41. i += 3;
  42. }
  43.  
  44. if (data[i+1] == 'm')
  45. {
  46. chat_usrs[data[i+5]] = new Array(chat_room, data[i+3], data[i+4], true);
  47. data[i+7] = data[i+7].replace(/%%(\w+)%%/g, '<img src="'+chat_path+'smileys/$1.gif" alt="" />');
  48. if (data[i+6] == '.')
  49. chat_msgs['.'] += '<span style="color: '+data[i+2]+'"><b>['+chat_date(-data[i+8])+'] '+chat_msgs_usr(data[i+5], data[i+2])+'</b>: '+data[i+7]+'</span><br />';
  50. else
  51. {
  52. chat_priv_prepair(data[i+5], data[i+6]);
  53. chat_msgs[data[i+5]][data[i+6]] += '<span style="color: '+data[i+2]+'"><b>['+chat_date(-data[i+8])+'] '+chat_msgs_usr(data[i+5], data[i+2])+'</b>: '+data[i+7]+'</span><br />';
  54. chat_msgs[data[i+6]][data[i+5]] += '<span style="color: '+data[i+2]+'"><b>['+chat_date(-data[i+8])+'] '+chat_msgs_usr(data[i+5], data[i+2])+'</b>: '+data[i+7]+'</span><br />';
  55. chat_wait[data[i+5]][data[i+6]] = false;
  56. chat_wait[data[i+6]][data[i+5]] = true;
  57. }
  58. i += 8;
  59. }
  60. }
  61.  
  62. if (data.length > 1)
  63. {
  64. chat_out_msgs();
  65. chat_out_usrs();
  66. }
  67. }
  68. }
  69. }
  70.  




Proszę o jakieś wskazówki, bo męczę się z tym już kilka godzin i pewnie jeszcze kilka się pomęcze (IMG:style_emoticons/default/smile.gif)

Dzięki z góry!
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: 22.08.2025 - 21:51