[Php-it] [OT] Le basi di Ajax
Angelo Galleja
angelo.galleja at email.it
Fri Jun 16 12:06:39 CEST 2006
innanzitutto
http://wiki.news.nic.it/QuotarBene
DierRe ha scritto:
> però è
> questo il problema: dentro un determinato div con un certo id ho dei
> collagamente (tag a). Quello di cui io necessito è generalizzare una
> funzione AJAX che faccia richiesta al server tale che come url da eseguire
> ci sia l href del collegamento che clicco.
qualcosa che ti carichi l'url del collegamento e lo butti nella
pagina "corrente"?
tuapagina.html
----cut----
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Titolo</title>
<script type="text/javascript">
/* cfr. georgenava.com */
function getXmlHttpObject() {
var http=false;
try {http=new XMLHttpRequest();} catch (e1){
try {http=new ActiveXObject("Msxml2.xmlhttp");} catch (e2){
try {http=new ActiveXObject("Microsoft.xmlhttp");} catch
(e3){http=false;}}}
return http;
}
function WebMethod(url,request,callback) {
var http = new XMLHttpRequest();
var mode = request?"POST":"GET";
http.open(mode,url,true);
if(mode=="POST"){http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');}
http.onreadystatechange=function(){if(http.readyState==4){callback(http.responseText);}};
http.send(request);
}
function init() {
document.getElementById('l').onclick = cliccato;
}
function cliccato() {
//alert('xx');
WebMethod('load.php?p=http://www.google.it', null, loaded);
}
function loaded(response) {
document.getElementsByTagName('body')[0].innerHTML = response;
}
</script>
</head>
<body onload="init()">
<a href="javascript:void(0);" id="l">Cliccami</a>
</body>
</html>
----cut----
load.php
----cut----
<?php
/**
* ----- ATTENZIONE ATTENZIONE -----
* usare questo codice in produzione e' una:
* http://www.demauroparavia.it/20406
*/
readfile($_GET['p']);
?>
----cut----
More information about the Php-it
mailing list