Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [JavaScript]Widget na windowsa i poobieranie danych z serwera z pliku
Saper82
post
Post #1





Grupa: Zarejestrowani
Postów: 37
Pomógł: 0
Dołączył: 11.07.2009

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


Witam

Piszę widget na windowsa, są one w javasript zrobione, została mi jedna rzecz do zrobienia w nim. Widget ma do zmiennej co 5 minut pobierać dane z pliku z serwera xx.xx.pl/plik.txt.

Macie pomysł jak to ugryźć?

Czytałem coś o ajax, php że tylko tak da się to zrobić, ale nic nie mogę konkretnego znaleźć.
Go to the top of the page
+Quote Post
SpiritCode
post
Post #2





Grupa: Zarejestrowani
Postów: 167
Pomógł: 35
Dołączył: 29.12.2014
Skąd: Otwock

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


  1. <script type="text/javascript">
  2. var plik;
  3. $.get('http://xx.xx.pl/plik.txt', function(data){
  4. window.plik = data;
  5. });


Tylko musisz mieć jQuery załadowane.
Nie potrzebny jest w zasadzie PHP, jeśli chcesz wyciągnąć dokładnie to co jest w pliku.
Go to the top of the page
+Quote Post
Saper82
post
Post #3





Grupa: Zarejestrowani
Postów: 37
Pomógł: 0
Dołączył: 11.07.2009

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


Nie bardzo mi to wychodzi to co podałeś.

Znalazłem inny sposób, jest to przykładowy kod, pobiera dane z pliku, ale jeśli zawartość pliku ulegnie zmianie to się nic zmienia w windgecie, dane są takie jak przy jego pierwszym uruchomieniu.
dane są pobierane z http://www.inik.pl/data.php
jest w nim wynik funkcji php time()
i w widgecie jest cały czas jedna wartość wyświetlana wzięta przy pierwszym uruchomieniu, ile razy bym nie uruchomił ponownie widgeta to nadal jest to sama wartość

macie pomysł jak temu zaradzić? Dlaczego po jego ponownym uruchomieniu nie jest pobierana nowa zawartość pliku?



  1. <style type="text/css">
  2. .styDefault {
  3. color: #999999;
  4. font-size: 9px;
  5. font-family: Verdana, Arial, Helvetica, sans-serif;
  6. }
  7.  
  8. .styTextBox {
  9. color: #000000;
  10. font-size: 11px;
  11. font-family: Verdana, Arial, Helvetica, sans-serif;
  12. margin:1px;
  13. border:1px;
  14. vertical-align:top;
  15. }
  16.  
  17. .styButton {
  18. color: #000000;
  19. font-size: 9px;
  20. font-family: Verdana, Arial, Helvetica, sans-serif;
  21. margin:0px;
  22. margin-left:2px;
  23. border:1px;
  24. vertical-align:top;
  25. }
  26.  
  27. .styImage {
  28. color: #000000;
  29. font-size: 9px;
  30. font-family: Verdana, Arial, Helvetica, sans-serif;
  31. margin:0px;
  32. margin-top:0px;
  33. margin-left:0px;
  34. border:0px;
  35. vertical-align:top;
  36. cursor:pointer;
  37. }
  38.  
  39. .styTable {
  40. color: #999999;
  41. font-size: 9px;
  42. font-family: Verdana, Arial, Helvetica, sans-serif;
  43. color: white;
  44. border-width: 0px;
  45. border-spacing: 0px;
  46. border-style: outset;
  47. border-color: white;
  48. border-collapse: separate;
  49. table-layout:fixed;
  50. }
  51. .styBody {
  52. background-image: url(images\\bckgrnd.png);
  53. background-repeat: no-repeat;
  54. margin-left: 0px;
  55. margin-top: 0px;
  56. margin-right: 0px;
  57. margin-bottom: 0px;
  58. }
  59.  
  60. <script type="text/javascript">
  61. function DoInit()
  62. {
  63. document.body.style.width = 160;
  64. document.body.style.height= 200;
  65. document.body.style.margin=0;
  66. getmyip();
  67. }
  68.  
  69. var t;
  70. function timerFn()
  71. {
  72. t=setTimeout("timerFn()",1000);
  73. }
  74.  
  75.  
  76. function createXMLHttpRequest()
  77. {
  78. if (window.ActiveXObject)
  79. {
  80. return(new ActiveXObject("Microsoft.XMLHTTP"));
  81. }
  82. else if (window.XMLHttpRequest)
  83. {
  84. return(new XMLHttpRequest());
  85. }
  86. }
  87.  
  88.  
  89. //function to process an XMLHttpRequest
  90. function process_ajax(phpPage, divID, getOrPost, async)
  91. {
  92. try
  93. {
  94. var xmlHttp = createXMLHttpRequest();
  95. var obj = document.getElementById(divID);
  96.  
  97. if(getOrPost == "get")
  98. {
  99. xmlHttp.open("GET",phpPage,true);
  100. xmlHttp.onreadystatechange = function()
  101. {
  102. if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
  103. {
  104. obj.innerHTML = xmlHttp.responseText;
  105. obj.innerHTML=obj.innerHTML+"ss";
  106. }
  107. }
  108.  
  109. xmlHttp.send(null);
  110. }
  111. }
  112. catch(err)
  113. {
  114. //do nothing
  115. }
  116. }
  117.  
  118. function process_ajax_sync(phpPage, getOrPost, async)
  119. {
  120. try
  121. {
  122. var xmlHttp = createXMLHttpRequest();
  123. var strRetVal="";
  124.  
  125. if(getOrPost == "get")
  126. {
  127. xmlHttp.open("GET",phpPage,true);
  128. xmlHttp.onreadystatechange = function()
  129. {
  130. if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
  131. {
  132. strRetVal = xmlHttp.responseText;
  133. }
  134. }
  135.  
  136. xmlHttp.send(null);
  137. }
  138. }
  139. catch(err)
  140. {
  141. //do nothing
  142. }
  143.  
  144. return(strRetVal);
  145. }
  146.  
  147. function getmyip()
  148. {
  149. var queryString = "http://www.inik.pl/data.php";
  150. var strResult = process_ajax_sync(queryString,"get",true);
  151. document.forms["frmIP"].txtIP.value=strResult;
  152. }
  153.  
  154. function getipdetails()
  155. {
  156. var queryString = "http://www.inik.pl/data.php";
  157. process_ajax(queryString,"ip2l_result","delete",true);
  158. process_ajax(queryString,"ip2l_result","get",true);
  159. }
  160.  
  161.  
  162. function roll_over(img_name, img_src)
  163. {
  164. document[img_name].src = img_src;
  165. }
  166.  
  167. function clear_all()
  168. {
  169. document.forms["frmIP"].txtIP.value="";
  170. document.getElementById("ip2l_result").innerHTML = "";
  171. }
  172.  
  173. <body onLoad="DoInit();" class="styBody">
  174. <table width="158" border="0" height="193" class="styTable" cellpadding="5" cellspacing="1" >
  175. <tr style="border:none; height:10px;">
  176. <td height="30" colspan="7">
  177. <form id="frmIP" style="border:none; margin:0px; margin-top:0px; margin-bottom:0px" >
  178. <input name="txtIP" type="text" class="styTextBox" id="id_txtIP" value="" maxlength="15" style="width:126px;"; /><img src='images\\search.png' name="imgsearch" title="Search for Location" alt="Search for Location" width="16" height="16" class="styImage" style="margin-left:2px" onmouseover="roll_over('imgsearch', 'images\\search_hover.png')" onmouseout="roll_over('imgsearch', 'images\\search.png')" onclick="getipdetails()" onkeypress="">
  179. </form>
  180. </td></tr>
  181. <tr>
  182. <td height="140" id="ip2l_result" colspan="7" style="vertical-align:top;"></td>
  183. </tr>
  184. <tr><td width="20" height="20"><img src="images\clear.png" name="imgclear" title="Clear All" alt="Clear All" class="styImage" width="16" height="16" onmouseover="roll_over('imgclear', 'images\\clear_hover.png')" onmouseout="roll_over('imgclear', 'images\\clear.png')" onclick="clear_all()"/></td>
  185. <td width="20"><img src="images\myip.png" name="imggetip" title="Get My IP Address" alt="Get My IP Address" class="styImage" width="16" height="16" onmouseover="roll_over('imggetip','images\\myip_hover.png')" onmouseout="roll_over('imggetip', 'images\\myip.png')" onclick="getmyip()"/></td>
  186. <td width="20"><a href="http://www.workmoment.com/?src=iptolocg"><img src="images\info.png"name="imginfo" title="WorkMoment Home" alt="WorkMoment Home" class="styImage" width="16" height="16" border="0" onmouseover="roll_over('imginfo', 'images\\info_hover.png')" onmouseout="roll_over('imginfo', 'images\\info.png')"/></a></td>
  187. <td width="20">&nbsp;</td>
  188. <td width="20">&nbsp;</td>
  189. <td width="20">&nbsp;</td>
  190. <td width="20">&nbsp;</td>
  191. </tr>
  192. </body>
  193. </html>


Ten post edytował Saper82 17.03.2015, 22:01:04
Go to the top of the page
+Quote Post

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: 23.12.2025 - 20:20