i want to get the alert on responce text, but getting nothing, my code is as follow,
<?php session_start(); ?>
<script type="text/javascript">
var xmlHttp
function checkCAP(str) {
if (str=="") {
alert("plase enter the code");
return
}
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null) {
alert ("Browser does not support HTTP Request")
return
}
var url="test.php"
url=url+"?id="+str
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
var response = xmlHttp.responseText;
if( response == "incorrect"){
alert(Please enter the right words);
}
}
}
function GetXmlHttpObject() {
var xmlHttp=null;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e) {
// Internet Explorer
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
</script>
<?php
if (!empty($_GET['id'])) {
include("securimage.php");
$img = new Securimage();
$valid = $img->check($_GET['id']);
if($valid == true) {
$responce = "correct";
} else {
$responce = "incorrect";
}
echo $responce;
} else { //form is posted
?>
<html>
<head>
<title>Securimage Test Form</title>
</head>
<body>
<form method="POST">
<!-- pass a session id to the query string of the script to prevent ie caching -->
<img src="securimage_show.php?sid=<?php echo md5(uniqid(time())); ?>"><br />
<input type="text" name="code" onblur= "return checkCAP(this.value);"/><br />
<input type="submit" value="Submit Form" />
</form>
<div id ="responce">Responce will be dispaly here</div>
<?php
}
?>
</body>
</html>
When i change the code as follow, i get all the source script in alert box...
function stateChanged(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
alert(xmlHttp.responceText);
}
}
}
but when i change the code as follow, it runs very much fine, it out puts PHP script result in the tag which reside in html part. but my application requirement is to get PHP out put in alert box.
function stateChanged(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("response").innerHTML = xmlHttp.responceText
}
}
is there any solution????