Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> JS + XMLHttpRequest nie działa jak należy
winuser
post 30.04.2011, 22:32:01
Post #1





Grupa: Zarejestrowani
Postów: 14
Pomógł: 0
Dołączył: 22.10.2010

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


Mam kod :

  1. <script language="JavaScript">
  2.  
  3. function processData(data) {
  4.  
  5. document.write(data);
  6. }
  7.  
  8. function handler() {
  9.  
  10. document.MainForm.fileURL.value = this.readyState;
  11.  
  12. if (this.readyState == 4)
  13. {
  14. processData(this.responseText);
  15. }
  16. }
  17.  
  18. function submitForm() {
  19.  
  20. var xhr = null;
  21.  
  22. try
  23. {
  24. xhr = new XMLHttpRequest();
  25. xhr.overrideMimeType('text/xml');
  26. }
  27. catch(e)
  28. {
  29. try
  30. {
  31. xhr = new ActiveXObject("Msxml2.XMLHTTP");
  32. }
  33. catch (e2)
  34. {
  35. alert("An exception occurred in the script. Error name: " + e.name + ". Error message: " + e.message);
  36. }
  37. }
  38.  
  39. xhr.onreadystatechange = handler;
  40.  
  41. xhr.open('GET','http://google.pl', true);
  42. xhr.send("");
  43.  
  44. }
  45.  
  46. </head>
  47.  
  48. <FORM method="POST" name="MainForm" action="">
  49. <INPUT type="text" name="fileURL" value="testURL">
  50. <INPUT type="submit" value="Pobierz" ONCLICK="submitForm()">
  51. </FORM>
  52. </body>
  53.  
  54. </html>


Dlaczego to nie działa ? Czasem daje w wyniku "1" a czasem "2" (w polu fileURL czyli wartość this.readyState).
Go to the top of the page
+Quote Post

Posty w temacie


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 Wersja Lo-Fi Aktualny czas: 18.07.2025 - 02:25