1 Replies - 141 Views - Last Post: 16 July 2013 - 12:56 AM Rate Topic: -----

#1 ankit1990rana  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 11-May 13

What is the error in the code ?

Posted 16 July 2013 - 12:48 AM

I am getting undefined at the place of the message

index.php
<!DOCTYPE html>
<head>
<script type="text/javascript" src="names.js"></script>
</head>

<body onload="process()">

        <h3>enter name</h3>
       
        <input type="text" id="input" />
        <div id="change" >nothing in here</div>

</body>
</html>



name.php
<?php
header('Content-Type: text/xml');
 echo '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>';

echo '<response>';
   $name=$_GET['name'];
   $names= array('ran','sham','ss','sdsd');
   
   if(in_array($name, $names)){
      echo "yes you are selected". $name;
      }elseif($name==''){
         echo 'say something ';
         }
         else{
            echo "no you are not".$name;
            }
   
   
echo '</response>';


?>


names.js
var xmlhttp = createobject();

function createobject(){
	var xmlhttp;
	
	if(window.ActiveXObject){
		try{
			xmlhttp = new ActiveXObject("Microsofe.XMLHTTP");
			}catch(e){
				xmlhttp = false;
				}
		
		}else{
			try{
			xmlhttp = new XMLHttpRequest();
			}catch(e){
				xmlhttp = false;
				}
			}
			if(!xmlhttp){
				alert("cannot create");
				}else{
					return xmlhttp;
					}
}

function process(){
	if(xmlhttp.readyState==0|| xmlhttp.readyState==4){
		name = encodeURIComponent(document.getElementById("input").value);
		xmlhttp.open("GET","names.php?names="+name,true);
		xmlhttp.onreadystatechange = response;
		xmlhttp.send(null);
		}else{
		alert("noooooo");
		setTimeout('process()',1000);
		}
	}

function response(){
   if(xmlhttp.readyState==4){
            if(xmlhttp.status==200){
               xmlResponse=xmlhttp.responseXML;
               xmlDocumentElement=xmlResponse.documentElement;
               message=xmlDocumentElement.firstChild.data;
               document.getElementById("change").innerHTML='<span style="color:blue">' +message + '</span>';
               setTimeout('process()', 1000);
         }else{
            alert('Something went wrong!');
            }
   }
   }


	


Is This A Good Question/Topic? 0
  • +

Replies To: What is the error in the code ?

#2 ankit1990rana  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 11-May 13

Re: What is the error in the code ?

Posted 16 July 2013 - 12:56 AM

neverminf got the error file name is names.php not name.php,,sorry guys
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1