Forum FAQForum FAQSearchSearch MemberlistMemberlist Forum ignore listForum ignore list RegisterRegister ProfileProfile Log in to check your private messagesLog in to check your private messages Log inLog in
Pokušaj AJAXA

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    mi3dot.org Forum Index -> Client-side
View previous topic :: View next topic  
Author Message
boby-s



Joined: 10 Apr 2004
Posts: 222
Location: Samobor< >Zagreb

PostPosted: 13.07.2007 14:42    Post subject: Pokušaj AJAXA Add user to your forum ignore list Reply with quote

Pokušavam malo petljati s ajaxom i našao sam na netu tutorial kako da komuniciram s php skriptom, problem je sljedeći, sve normalno radi u Firefoxu i IE 5+, ali u Operi ne (najnovijoj)

Ako netko moze pogledati i reci u cem je problem, bio bih jako zahvalan.

(Skripta traži vrijeme od servera preko php-a i vraća natrag klijentu)

Skripta se nalazi na http://thereis.myftp.org/ajax/ajax.html

A kod je ovakav

Code:
<html>
<body>

<script language="javascript" type="text/javascript">
<!--
//Browser Support Code
function ajaxFunction(){
   var ajaxRequest;  // The variable that makes Ajax possible!
   
   try{
      // Opera 8.0+, Firefox, Safari
      ajaxRequest = new XMLHttpRequest();
   } catch (e){
      // Internet Explorer Browsers
      try{
         ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
         try{
            ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
         } catch (e){
            // Something went wrong
            alert("Your browser broke!");
            return false;
         }
      }
   }
   // Create a function that will receive data sent from the server
   ajaxRequest.onreadystatechange = function(){
      if(ajaxRequest.readyState == 4){
         /*document.myForm.time.value = ajaxRequest.responseText;*/
         document.getElementById("tekst").innerHTML = ajaxRequest.responseText;
         setTimeout(ajaxFunction,1000);
      }
   }
   ajaxRequest.open("GET", "serverTime.php", true);
   ajaxRequest.send(null);
}

//-->
</script>

<script>ajaxFunction();</script>

<div id="tekst"></div>

</body>
</html>


php:
Code:
<?php
echo date("H:i:s");
?>
Back to top
View user's profile Send private message
sloser



Joined: 13 Jul 2007
Posts: 14

PostPosted: 13.07.2007 21:13    Post subject: ajax Add user to your forum ignore list Reply with quote

bas sam htio pogledati zasto ovo ne radi u operi, ali na linux-u u operi radi...
Back to top
View user's profile Send private message
zytzagoo
mi3.crew


Joined: 25 Aug 2003
Posts: 1842
Location: Zagreb, Hrvatska

PostPosted: 13.07.2007 22:16    Post subject: Add user to your forum ignore list Reply with quote

radi i na windowsima... Opera 9.21
EDIT: da ti nije iskljucen javascript u Operi? ili neki security option?

_________________
[+]I[+]am[+]my[+]own[+]religion[+]
Back to top
View user's profile Send private message Visit poster's website Twitter profile
boby-s



Joined: 10 Apr 2004
Posts: 222
Location: Samobor< >Zagreb

PostPosted: 15.07.2007 09:26    Post subject: Add user to your forum ignore list Reply with quote

nisam siguran dal ste shvatili, skripta bi trebala (setTimeout(ajaxFunction,1000)Wink svakih sekundu prikazati novo vrijeme...

sekundu po sekundu...

u firefoxu 2.0 radi kak se spada Smile

Quote:
u operi samo stoji...kad se refresha, vrijeme je isto kao i prije


edit: u postavkama sam prčkao po cacheu i redrawu stranice, i sad sve radi Smile

Quote:
u ie7 samo stoji...kad se refresha, nema ničeg


edit2: evo ista stvar i sa IE7, promijenio sam u Tools > Internet Options > History (Temporary files) da ne cachea nego da stalno provjerava za novi content na stranici i sad sve isto tako radi...čudno


Moram napomenuti da su sve ovo DEFAULTNE postavke programa...
Postoji li način da spriječim da se to dogodi i nekome drugom tko posjeti takvu stranicu, ili?


btw. Hvala dečki na trudu Wink
Back to top
View user's profile Send private message
boby-s



Joined: 10 Apr 2004
Posts: 222
Location: Samobor< >Zagreb

PostPosted: 15.07.2007 09:43    Post subject: Add user to your forum ignore list Reply with quote

Budući da sam isprobavao gro stvari i skripti...ima još jedna koja po defaultu radi na Firefoxu i Operi a ne u IE7, no otkad sam uključio ono gore, radi i ova.

http://thereis.myftp.org/ajax/ajax2.html

Code:
Firefox i Opera ok <br />
IE7 not
<!DOCTYPE  HTML  PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javascript" type="text/javascript">
var xmlHttp;
function createRequest(){
 

if(window.ActiveXObject){
 

xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
 

}
else if(window.XMLHttpRequest){
 

xmlHttp = new XMLHttpRequest();
 

}
 

}
function ajax(){
 

createRequest();
var url = "ajax2.php?test=hello!";
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = StateChange;
xmlHttp.send(null);
 

}
function StateChange(){
 

if(xmlHttp.readyState == 4){
 

/*alert(xmlHttp.responseText);*/
document.getElementById('tekst').innerHTML = xmlHttp.responseText;
setTimeout(ajax,1000);
 

}}
 
</script>
</head>
<body>
<script>ajax();</script>
<div id="tekst"></div>
</body>
</html>


Možete li mi reći koju je pametnije koristiti i zašto?
btw. php fajl je isti.
Back to top
View user's profile Send private message
velcro



Joined: 15 Sep 2004
Posts: 116

PostPosted: 15.07.2007 10:25    Post subject: Add user to your forum ignore list Reply with quote

Nisam probao tvoju skriptu - al ako je problem u cachiranju, mozes probati pozivati url s random brojem iza njega sto ce osigurati da ga browser ne cachira.

npr. dodas:
Code:
var d = new Date();


i jos promijenis onu jednu postojecu liniju u:
Code:
ajaxRequest.open("GET", "http://thereis.myftp.org/ajax/serverTime.php?"+d.valueOf(), true);
Back to top
View user's profile Send private message
zytzagoo
mi3.crew


Joined: 25 Aug 2003
Posts: 1842
Location: Zagreb, Hrvatska

PostPosted: 15.07.2007 12:05    Post subject: Add user to your forum ignore list Reply with quote

Ili na serverskoj strani serviras content sa no-cache headerima. I jedan i drugi pristup imaju
svojih prednosti i mana.

php manual za no-cache headere:
Code:
<?php
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// always modified
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
// HTTP/1.0
header("Pragma: no-cache");

echo date("H:i:s");
?>

_________________
[+]I[+]am[+]my[+]own[+]religion[+]
Back to top
View user's profile Send private message Visit poster's website Twitter profile
Sulien



Joined: 04 Jan 2004
Posts: 2905
Location: Zagreb

PostPosted: 15.07.2007 13:43    Post subject: Re: Pokušaj AJAXA Add user to your forum ignore list Reply with quote

Code:
<?php
header('Cache-Control: no-cache');
header('Expires: ' . gmdate(DATE_RFC1123));
echo date("H:i:s");
?>


brijem dovoljno?
Back to top
View user's profile Send private message Send e-mail Visit poster's website
boby-s



Joined: 10 Apr 2004
Posts: 222
Location: Samobor< >Zagreb

PostPosted: 15.07.2007 17:20    Post subject: Add user to your forum ignore list Reply with quote

Oo hvala ekipa Wink
Quote:

Zanimljiv pristup, u teoriji, budem isprobao u praksi pa cemo vidjeti...jako zanimljivo, nema šta...


Sva navedena rješenja stvarno rade, hvala lijepo svima na trudu još jednom Wink
Back to top
View user's profile Send private message
maratz
mi3.crew


Joined: 24 Nov 2003
Posts: 1207
Location: ZAG

PostPosted: 19.07.2007 02:53    Post subject: Add user to your forum ignore list Reply with quote

Vezano uz testiranje objekta...

window.XMLHttpRequest je manje ubojit za stroj od nestane try/catch nesreće iz prvog primjera...

Last edited by maratz on 24.07.2007 08:00; edited 1 time in total

_________________
STOP HITTING YOURSELF! | NETIQUETTE | TYPETESTER | Hypertext rulez™ | CREATIVE NIGHTS | ACCOMMODATIONS
Back to top
View user's profile Send private message Visit poster's website Twitter profile
boby-s



Joined: 10 Apr 2004
Posts: 222
Location: Samobor< >Zagreb

PostPosted: 22.07.2007 13:48    Post subject: Add user to your forum ignore list Reply with quote

maratz wrote:
Vezano uz testiranje objekta...

window.XMLHttpRequest je manje ubojit za stroj od nestane try/catch nesreće iz prvog primjera...[/b]


koliko točno manje ubojit?
već sam sve napravio sa

Code:
   try{
      // Za Operu, Firefox, Safari
      ajaxRequest = new XMLHttpRequest();
   } catch (e){
      // Za Internet Explorer
      try{
         ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
         try{
            ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
         } catch (e){
            // Ups...wtf?
            alert("Vaš internet preglednik ne podržava \"XMLHttpRequest\".<br />Molimo koristite Operu 8+,Firefox 1.5+,IE 5+");
            return false;
         }
      }
   }


kako bi to prepisao u ovo što ti predlažeš?[/quote]
Back to top
View user's profile Send private message
maratz
mi3.crew


Joined: 24 Nov 2003
Posts: 1207
Location: ZAG

PostPosted: 24.07.2007 08:20    Post subject: Add user to your forum ignore list Reply with quote

boby-s wrote:
kako bi to prepisao u ovo što ti predlažeš?


Testirao bi window.XMLHttpRequest, odnosno window.ActiveXObject, pa ako postoji ActiveX objekt, probao bi mu predati Msxml2.XMLHTTP, odnosno Microsoft.XMLHTTP argument. Ima brojnih primjera osnovnog testiranja XHR-a, možeš krenuti i na Wikipediji: http://en.wikipedia.org/wiki/XMLHttpRequest

_________________
STOP HITTING YOURSELF! | NETIQUETTE | TYPETESTER | Hypertext rulez™ | CREATIVE NIGHTS | ACCOMMODATIONS
Back to top
View user's profile Send private message Visit poster's website Twitter profile
boby-s



Joined: 10 Apr 2004
Posts: 222
Location: Samobor< >Zagreb

PostPosted: 12.08.2007 12:59    Post subject: Add user to your forum ignore list Reply with quote

u stvari, meni je više potrebna brzina i kompaktnost koda (da ga je što manje Smile)
a manje mi je potrebna podrška za ie manji od verzije 7

kopajući uokolo, saznao sam da ie7 podržava XMLHttpRequest i bez activeX-a tako da ovaj try/catch leti definitivno van Smile

ukoliko će mi biti potreban support za ie manji od 7ce, namjeravam iskoristiti ovo
http://design-noir.de/webdev/JS/XMLHttpRequest-IE/
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    mi3dot.org Forum Index -> Client-side All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group