Jump to content

Didn't undestand PHP with Ajax and XML


calande

Recommended Posts

I'm having a hard time understanding the Ajax + XML + PHP tutorials, so off we go! Here are my questions:Here first: PHP and AJAX responseXML Example

if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")

Under what circumstances can xmlHttp.readyState be equal to complete ?

xmlDoc=xmlHttp.responseXML;document.getElementById("firstname").innerHTML=xmlDoc.getElementsByTagName("firstname")[0].childNodes[0].nodeValue;

What is xmlHttp.responseXML ?What is getElementsByTagName("firstname")[0].childNodes[0] ?And then here: PHP and AJAX XML Example

$x=$xmlDoc->getElementsByTagName('ARTIST');

What is this $x variable?

for ($i=0; $i<=$x->length-1; $i++)

Ok, let me understand this: You instanciate a $i variable with 0, then you run the loop until $i reaches the value of $x but then what is this ->length-1 ?

if ($x->item($i)->nodeType==1)

Same problem here with ->. Isn't -> used to access methods in classes? Then what does the above code mean?Thanks in advance for your patience :)

Link to comment
Share on other sites

Under what circumstances can xmlHttp.readyState be equal to complete ?
I can't find a reason. Some browser somewhere might use "complete", but checking for 4 is probably sufficient.
What is xmlHttp.responseXML ?
The responseXML property is an XML representation or structure of the server's response. responseXML is only available if the server sends the mime type of the response as text/xml. For plain text or HTML documents, the responseText property should be used. The Opera browser makes an exception, in that it will populate responseXML for HTML documents as well.
What is getElementsByTagName("firstname")[0].childNodes[0] ?
This refers to the first child of the first tag called "firstname". It would look something like this:
<xml>  <firstname>	<first_child>

It refers to the first child of the first "firstname" tag, in this case "first_child".

What is this $x variable?
$x is the return value of the getElementsByTagName function, which probably returns an object containing all of the elements of a given tag name, in this case "ARTIST".
Ok, let me understand this: You instanciate a $i variable with 0, then you run the loop until $i reaches the value of $x but then what is this ->length-1 ?
$x is an object, not a value. The value it is checking is $x->length minus 1, meaning that the $x object has a property called length, and it is referenced by $x->length.
if ($x->item($i)->nodeType==1)Same problem here with ->. Isn't -> used to access methods in classes? Then what does the above code mean?
This is checking if the nodeType property of an item in the $x object has the value of 1. The item method of the $x object returns another object which has a nodeType property, that property is being tested.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...