tema XMLHttpRequest

Discutii legate de AJAX, jQuery, MooTools, Prototype, Dojo, Yahoo! UI Library,script.aculo.us, ExtJS,AngularJS, Backbone.js, Ember.js, KnockoutJS

Moderator: Moderatori

Avatar utilizator
oriceon
PHPRomania Moderator
Mesaje: 480
Membru din: Vin Dec 24, 2004 3:48 pm
Localitate: Constanta
Contact:

tema XMLHttpRequest

Mesajde oriceon » Mie Apr 05, 2006 7:02 pm



.:: Develop and Fun in .Ro Style ::.
I love and i enjoy browsing web with

coditza
Senior Member
Mesaje: 298
Membru din: Vin Ian 23, 2004 7:30 pm
Localitate: cluj-napoca

Mesajde coditza » Mie Apr 05, 2006 7:52 pm

Iara ai scapat in vadra de vin? :P
function foo() { foo(); }

Avatar utilizator
oriceon
PHPRomania Moderator
Mesaje: 480
Membru din: Vin Dec 24, 2004 3:48 pm
Localitate: Constanta
Contact:

Mesajde oriceon » Mie Apr 05, 2006 7:57 pm

.:: Develop and Fun in .Ro Style ::.

I love and i enjoy browsing web with

coditza
Senior Member
Mesaje: 298
Membru din: Vin Ian 23, 2004 7:30 pm
Localitate: cluj-napoca

Mesajde coditza » Mie Apr 05, 2006 8:34 pm

sa vad vinuuuuuuuuuu :P
function foo() { foo(); }

Avatar utilizator
black diamond
Senior Member
Mesaje: 298
Membru din: Lun Mai 23, 2005 8:42 pm
Contact:

Mesajde black diamond » Mie Apr 05, 2006 8:40 pm

index.php
[php]
<html>
<head>
<title>AJAX test</title>
<script type="text/javascript" src="js.js"></script>
</head>
<body>
<p><a href="javascript:sndReq('Kia Ora')">[Kia Ora]</a> |
<a href="javascript:sndReq('Bula')">[Bula]</a> |
<a href="javascript:sndReq('Bonjour')">[Bonjour]</a>
<a href="javascript:sndReq('Valy')">[VAly???]</a></p>
<p> </p>
<div id="foo"> </div>
</body>
</html>
[/php]

js.js
[php]
function createRequestObject() {
var ro;
try {
if (window.XMLHttpRequest) ro = new XMLHttpRequest()
else ro = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(er) {
alert('Ajax is not available for this browser');
}
return ro;
}
var http = createRequestObject();

function sndReq(action) {
http.open('get', 'rpc.php?action='+action);
http.onreadystatechange = handleResponse;
http.send(null);
}

function handleResponse() {
if(http.readyState == 4){
var response = http.responseText;
var update = new Array();
if(response.indexOf('|') != -1) {
update = response.split('|');
changeText(update[0], update[1])
}
}
}

function changeText( div2show, text ) {
// Detect Browser
var IE = (document.all) ? 1 : 0;
var DOM = 0;

if (parseInt(navigator.appVersion) >=5) {DOM=1};

if (DOM) {
var viewer = document.getElementById(div2show)
viewer.innerHTML=text
}
else if(IE) {
document.all[div2show].innerHTML=text
}

}

[/php]

rpc.php
[php]
<?php
header("Cache-Control: no-cache");
header("Pragma: nocache");
switch($_REQUEST['action']) {
case 'Kia Ora':
$output = "New Zealand";
break;
case 'Bula':
$output = 'Fiji';
break;
case 'Bonjour':
$output = 'France';
break;
case 'Valy':
$output = 'Valy Rullz';
break;
}
$output = "foo|<font color='navy'>{$output} < < " . time() . ' >> ';
echo $output;
?>
[/php]

opera 9beta, ie 6, firefox 1.5.0.1
|
p.s. pentru anumite lucruri trebuie un dram de logica si rabdare... sau o cautare scurta pe net. faceti uz de google!

Avatar utilizator
oriceon
PHPRomania Moderator
Mesaje: 480
Membru din: Vin Dec 24, 2004 3:48 pm
Localitate: Constanta
Contact:

Mesajde oriceon » Joi Apr 06, 2006 9:51 am

Mersi domnule diamant.

Se pare ca problema mea consta in ...

[php]
header("Cache-Control: no-cache");
header("Pragma: nocache");
[/php]

... pentru ca mie imi scria o singura data ... nu tot timpul ...

Now, seems that`s ok, thanks again.


Un vin si pt codita si pt tine :)
.:: Develop and Fun in .Ro Style ::.

I love and i enjoy browsing web with

carco
Senior Member
Mesaje: 2799
Membru din: Joi Mai 27, 2004 4:36 pm
Localitate: Bucuresti
Contact:

Mesajde carco » Joi Apr 06, 2006 10:18 am

Vreau si eu vin!

index.php
[php]
<?='<?xml version="1.0" encoding="utf-8"?>'?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Simple AJAX</title>
<script type="text/javascript">
/*<![CDATA[*/
function scrie() {
var d = new Date();
var bug = document.getElementById('bug');
document.getElementById('wait').style.display='inline';
bug.src='scrie.php?'+d.getTime()+Math.random();
bug.onload=function() {document.getElementById('wait').style.display='none';}
}
/*]]>*/
</script>
</head>
<body>
<p>
<a href="index.php?status=nojavascript" onclick="scrie(); return false;">scrie</a>
</p>

<p>
<img id="bug" src="<?=empty($_GET['status'])?'ok.png':'scrie.php'?>" alt="." />
<small id="wait" style="display:none">asteptati...</small>
</p>
</body>
</html>
[/php]

scrie.php
[php]
<?php
header('Content-Type: image/png');
sleep(3); //comment this
if(!$x=@fopen("test.txt", "a+")) {
readfile('no.png');
return false;
}
if(!@fwrite($x, "a")) {
readfile('no.png');
return false;
}
@fclose($x);
readfile('ok.png');
?>
[/php]

Nota:
- in loc de ok.png/no.png se poate folosi un bug (un gif transparent de 1x1 pixeli)
- Intrebare pentru specialistii in javascript, exista posibilitatea de a vedea cumva ce dimensiune are o imagine care e pusa ca src? (in ideea de a comunica erorile prin imagini de dimensiuni diferite)
Programator cu experienta in Magento/ZF, Typo3/Flow3, Symfony, B2B, CRM, ERP, SMB... vand betoniera

Avatar utilizator
black diamond
Senior Member
Mesaje: 298
Membru din: Lun Mai 23, 2005 8:42 pm
Contact:

Mesajde black diamond » Joi Apr 06, 2006 3:22 pm

|

p.s. pentru anumite lucruri trebuie un dram de logica si rabdare... sau o cautare scurta pe net. faceti uz de google!

deVries
PHPRomania Supporter
Mesaje: 13
Membru din: Lun Apr 10, 2006 9:04 pm

Mesajde deVries » Lun Apr 10, 2006 9:29 pm


carco
Senior Member
Mesaje: 2799
Membru din: Joi Mai 27, 2004 4:36 pm
Localitate: Bucuresti
Contact:

Mesajde carco » Lun Apr 10, 2006 10:58 pm

am auzit ca nu ai cum... de ce nu folosesti un iframe?
Programator cu experienta in Magento/ZF, Typo3/Flow3, Symfony, B2B, CRM, ERP, SMB... vand betoniera


Înapoi la “Librarii Javascript”

Cine este conectat

Utilizatori ce ce navighează pe acest forum: Niciun utilizator înregistrat și 1 vizitator