Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [xmlhttp/js] Kompatybilność przeglądarek.., Kod działa tylko pod ie;/
katsuo
post
Post #1





Grupa: Zarejestrowani
Postów: 18
Pomógł: 1
Dołączył: 1.05.2007

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


Hi!
Kod :
  1. <head>
  2. <script type="text/javascript">
  3. <!--
  4. function submitForm(){
  5. var xhr;
  6. if (window.XMLHttpRequest) {
  7. xhr = new XMLHttpRequest();
  8. alert('opera');
  9. }
  10. else if (window.ActiveXObject) {
  11. try {
  12. xhr= new ActiveXObject("Msxml2.XMLHTTP");
  13. }
  14. catch (e){
  15. try{
  16. xhr = new ActiveXObject("Microsoft.XMLHTTP");
  17. }
  18.  
  19. catch(e3){
  20. xhr=false;
  21. }
  22. }
  23. }
  24. xhr.open('POST','data.txt',true);
  25. xhr.send(null);
  26. xhr.onReadyStateChange=processReqChange();
  27. function processReqChange(){
  28. alert(xhr.readyState);
  29. if(xhr.readyState == 4){
  30. alert('test2');
  31. if(xhr.status == 200){
  32. var doc = xhr.responseTEXT;
  33.  
  34. alert('test3');
  35. document.getElementById('element1').innerHTML= doc; // Assign the content to the form
  36. alert( xhr.status);
  37. }
  38. else{
  39. document.getElementById('element1').innerHTML="Kod błędu: "+xhr.status;
  40. }
  41. }
  42. }
  43. }
  44. -->
  45. </script>
  46. </head>
  47. <body onLoad="submitForm();" >
  48. <div id="element1" ></div>
  49. </body>
  50. </html>


Zachowanie:
- IE 6.0: wyświetla treść pliku data.txt
- firefox 3.0.5: zamiast podmienić element1 na tresc- wyświetla 'undefinied'
- opera 9.63: nic nie wyświetla.

Problem pewnie banał, jednak byłbym bardzo wdzięcznym za pomoc:)

Pzdr.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
chyzio
post
Post #2





Grupa: Zarejestrowani
Postów: 93
Pomógł: 0
Dołączył: 12.03.2006

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


a ja mam następujące pytanie zuwagi na którą funkcję kod musi być uruchamiany z serwera (kod oczywiście działa ale po uruchomieniu go z serwera)

  1. <script type="text/javascript">
  2. <!--
  3. function GetXmlHttpObject()
  4. {
  5. var xmlHttp=null;
  6. try
  7. {
  8. // Firefox, Opera 8.0+, Safari
  9. xmlHttp=new XMLHttpRequest();
  10. }
  11. catch (e)
  12. {
  13. // Internet Explorer
  14. try
  15. {
  16. xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  17. }
  18. catch (e)
  19. {
  20. xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  21. }
  22. }
  23. return xmlHttp;
  24. }
  25.  
  26. function submitForm($param){
  27. var wybor = $param;
  28. xmlHttp = GetXmlHttpObject();
  29. if (xmlHttp == null) {
  30. alert ("Your browser does not support AJAX!");
  31. return;
  32. }
  33. xmlHttp.onreadystatechange=processReqChange;
  34.  
  35.  
  36. switch (wybor) {
  37.  
  38. case 'home':
  39. xmlHttp.open("post","articles/home.html",true);
  40. document.getElementById('map').style.display='none';
  41. break
  42. case 'area':
  43. xmlHttp.open("post","articles/area.html",true);
  44. document.getElementById('map').style.display='block';
  45. break
  46. case 'tariffs':
  47. xmlHttp.open("post","articles/tariffs.html",true);
  48. document.getElementById('map').style.display='none';
  49. break
  50. case 'cars':
  51. xmlHttp.open("post","articles/cars.html",true);
  52. document.getElementById('map').style.display='none';
  53. break case 'contact':
  54. xmlHttp.open("post","articles/contact.html",true);
  55. document.getElementById('map').style.display='none';
  56. break
  57. case 'booking':
  58. xmlHttp.open("post","articles/booking.html",true);
  59. document.getElementById('map').style.display='none';
  60. break
  61. }
  62.  
  63. xmlHttp.send(null);
  64. }
  65.  
  66. function processReqChange() {
  67. //alert(xmlHttp.readyState);
  68. //document.getElementById('e2').innerHTML=xmlHttp.readyState;
  69. if(xmlHttp.readyState == 4){
  70. //alert('test2');
  71. if(xmlHttp.status == 200){
  72. var doc = xmlHttp.responseText;
  73. //alert('test3');
  74. //alert(doc);
  75. document.getElementById('element1').innerHTML = doc; // Assign the content to the form
  76. //alert(xhr.status);
  77. }
  78. else{c
  79. document.getElementById('element1').innerHTML="Kod bledu: "+xmlHttp.status;
  80. }
  81. }
  82. }
  83. -->
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: 16.10.2025 - 01:49