I am confuse about the sequence of

Does the following lines get's executed in the begining or the end;  


xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();

http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_first

<html>
<head>
<script type="text/javascript">
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
}
</script>
goodkAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

StingRaYCommented:
xmlhttp.send() will execute GET operation to ajax_info.txt defined in xmlhttp.open()

is this what you ask?
goodkAuthor Commented:
when does this gets called;  
xmlhttp.onreadystatechange=function()

what is sequence of the execution of the example.

thanks
StingRaYCommented:
Once send() command is executed asynchronously, the onreadystatechange will be triggered when xmlhttp request end with receiving some data or getting an error.

You can check if the data is returned by checking readyState == 4 and status == 200.
If both conditions are true, you can access responseText for the returned string.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

goodkAuthor Commented:
got that,

What about the following part?  The sequence still seems confusing.  What is throwing me off is the function inside the function?

var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
goodkAuthor Commented:
thanks
StingRaYCommented:
Ok, the part you mention above is just assignment part. It is to assign XMLHTTP object to xmlhttp variable by testing if window.XMLHttpRequest is available or not which is available in IE7+, Firefox, Chrome, Opera and Safari while the else part is for IE5 and 6.

The xmlhttp.onreadystatechange=function()... is also an assignment to bind a given function to an event.
goodkAuthor Commented:
if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById(VarmyDiv).innerHTML=xmlhttp.responseText;
    }


What if myDiv was a variable, VarmyDiv?  How do we pass the value to it when we call the

 loadXMLDoc(string VarmyDiv)?? thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
AJAX

From novice to tech pro — start learning today.