HTTP GET request in JavaScript? -


i need http get request in javascript. what's best way that?

i need in mac os x dashcode widget.

you can use functions provided hosting environment through javascript:

function httpget(theurl) {     var xmlhttp = new xmlhttprequest();     xmlhttp.open( "get", theurl, false ); // false synchronous request     xmlhttp.send( null );     return xmlhttp.responsetext; } 

however, synchronous requests discouraged, might want use instead:

function httpgetasync(theurl, callback) {     var xmlhttp = new xmlhttprequest();     xmlhttp.onreadystatechange = function() {          if (xmlhttp.readystate == 4 && xmlhttp.status == 200)             callback(xmlhttp.responsetext);     }     xmlhttp.open("get", theurl, true); // true asynchronous      xmlhttp.send(null); } 

note: starting gecko 30.0 (firefox 30.0 / thunderbird 30.0 / seamonkey 2.27), synchronous requests on main thread have been deprecated due negative effects user experience.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -