View Single Post
Old 01-31-2012, 08:38 PM   PM User | #1
objet
New to the CF scene

 
Join Date: Oct 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
objet is an unknown quantity at this point
why readyState equal to zero

Hi,

the line 95
Code:
if (xhr.readyState == 4) {
equal to zero in function setWord();
1 - why ?
2 - did the browser run the code and when it come to line 95
it run but just one time if readyState equal to 4 the browser
continue successfully else (readyState equal to 0-3 ) then the browser will skip it and not wait to readyState parameter that will be equal to 4
Thanks ;

the code:
Code:
	var str = "";
	var getString = "";
	var tempDiv = "";
	var newWord = "";
	var xhr = false;
	var url = "Favorite_Word.xml";
	var msg = "";
	var i,a;
	
	
	
function initAll() {
		
	str = document.getElementById("word").value;
	document.getElementById("word").className = "";
	
	 if (str != ""){
	 	i = str.length;
	 	a = i;
	 	getstring = "";
	 	tempDiv = "";
	 	newWord = "";
	 	checkFullInputField();
	 }
}

function checkFullInputField(){
	if_There_Request_XML();
	 if (newWord!=""){
	 	while (i>0&&i<=mycars[0].length)
  			 {
  			  msg ="i:=" + i + "' a=i:=" + a;popmenu();
  			   if (str[a-i].toLowerCase()== mycars[0][a-i].toLowerCase())
			       {msg ="a - i= " + (a-i) + " ," + "i:= " + i + " " + " ,First str="+ str[a-i];popmenu();
				    getstring=getstring+str[a-i].toLowerCase();
				    i--;}
  			    else {msg ="you are in else i:= " + i;popmenu();i=-5;}

  			 }
			 if (i==0){msg = "inputfield.getstring=" + getstring;popmenu();}
			     else {msg = "inputfield.getstring=" + getstring + "<br />"+"inputfield_str_1:" + str.substring(0,getstring.length);popmenu();}
	 }
}



function popmenu(){
		 
	document.getElementById("popups").innerHTML = "";
	var tempDiv = document.createElement("div");
				tempDiv.innerHTML = msg;
				tempDiv.className = "suggestions";
				document.getElementById("popups").appendChild(tempDiv);
}

function if_There_Request_XML(){
	 getHTTPObject();	
		alert("There is xhr :=2");
		if (xhr) {
		xhr.onreadystatechange = setWord();
		xhr.open("GET", url, true);
		xhr.send(null);
		alert("There is if xhr :=6");
	}
	else {
		alert("Sorry, but I couldn't create an XMLHttpRequest");
	}
}

function getHTTPObject()
{
  
	 if (window.XMLHttpRequest) {
		xhr = new XMLHttpRequest();
		alert("There is getHTTPObject firefox:=1");
	}
	else {
		if (window.ActiveXObject) {
			try {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) { }
		}
	}
}

function setWord() {
	var Node1 = "student";
	var Node2 = "name";

	if (xhr.readyState == 4) {
		if (xhr.status == 200) {
			if (xhr.responseXML) {

				var wordData = xhr.responseXML.getElementsByTagName(Node1);
				       alert("wordData:=" + wordData + ":=5 " );         
                        newWord = wordData[0].getElementsByTagName(Node2)[0].firstChild.nodeValue;
					        alert("newWord:=" + newWord );
				}
			}
		}
		else {
			alert("There was a problem with the request " + xhr.status + ":=3 4");
		}
	}
objet is offline   Reply With Quote