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
katsuo
post
Post #2





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

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


Teraz działa ładnie, dzięki. (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
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: 27.09.2025 - 09:17