General Question
Ajax beginner,need help!
———————
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’;
?>
2 Answers
Answer this question
This question is in the General Section. Responses must be helpful and on-topic.