Send to a Friend

stephen's avatar

Ajax beginner,need help!

Asked by stephen (351points) January 1st, 2009

———————
ajax.html
———————
<script type=“text/javascript”>
function createXHR(){
var xmlHtttpObj;
if(window.XMLHttpRequest){
xmlHtttpObj=new XMLHttpRequest();
}else{
try{
xmlHtttpObj=new ActiveXObject(“Msxml2.XMLHTTP”);
}
catch(e){
try{
xmlHtttpObj=new ActiveXObject(“Microsoft.XMLHTTP”);
}
catch(e){
xmlHtttpObj=false;
}
}
}
return xmlHtttpObj;
}
var xmlHttp=null;
function sendRequest(){
if(!xmlHttp) xmlHttp=createXHR();
if(!xmlHttp) return;
var url=’./handle.php?x=e’;
xmlHttp.open(‘GET’,url,true);
xmlHttp.onreadystatechange=handleBack;
xmlHttp.send(null);

}

function handleBack(){
/* alert(‘handleback’);
if(!xmlHttp) alert(‘bad reqeuest’);
else{
alert(‘good request’);
alert(xmlHttp.readyState);
alert(xmlHttp.status); //always alert 0 ????
}*/alert(xmlHttp.status);
if(xmlHttp.readyState==4){

alert(xmlHttp.responseText);//alert:<?php echo ‘test’; ?>,??? check the pic:
}
}
</script>
</head>

<body>
<a href=”##” onclick=“sendRequest()”>send request</a>
</body>

———————
handle.php:
———————
<?php
echo ‘test’;
?>

Using Fluther

or

Using Email

Separate multiple emails with commas.
We’ll only use these emails for this message.