Javascript alternative of jquery load() -
can please give me example of pure javascript alternative jquery load() ? or point me rite site example.
thank you
update:
this not meant ask. need use ajax load url , insert returned html 'div'
i don't quite negative points. @ least care explain wrong question? search on , not find example.
in order make ajax requests using pure javascript, need this:
httprequest = new xmlhttprequest(); // specify function handle response. httprequest.onreadystatechange = function() { // process ajax response in here. } // make ajax request httprequest.open('get', 'http://prajjwal.com/profile.json', true);
the first parameter open type of request want make. make 'get' request in case. second argument url of item you're trying retrieve. third argument boolean decides whether request should asynchronous or not. if request async, function not halt & wait request finish.
it worth noting won't work in internet explorer 8 or below. support browsers, need use:
httprequest = new activexobject("microsoft.xmlhttp");
to handle response, handler needs have this:
function handlerequest() { if (httprequest.readystate === 4) { if (httprequest.status === 200) { yourdiv.innerhtml = httprequest.responsetext; } else { console.log('there problem request.'); } } } httprequest.onreadystatechange = handlerequest;
httprequest.readystate tells how request progressing. value of 4 means request complete & ready processed.
keep in mind cannot request resources on other domains open().
Comments
Post a Comment