AJAX Raw Javascript Basic -


i wonder why open , send method when using ajax comes @ end. not before responsetext method

function loadxmldoc() { if (window.xmlhttprequest)   {// code ie7+, firefox, chrome, opera, safari   xmlhttp=new xmlhttprequest();   } else   {// code 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","xmlhttp_info.txt",true); xmlhttp.send(); } 

i'm bit confused open method take url of our data/file. , how xmlhttp.responsetext method file we're working with, since code @ bottom –

basically need construct request @ first , bind necessary event handlers process response. need fire request. that's reason why it's @ end.

if fire request @ first, might not have event handlers registered handle response.

so that's reason why @ first constructing xhr object , binding event hanlders using xmlhttp.onreadystatechange.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -