Synchronous AJAX Request in Vanilla Javascript

– 07/01/13

Sometimes you need to make a really quick synchronous AJAX request. Sometimes you don’t have jQuery at your disposal.

When you’re in this situation, here’s a little code snippet to help you out.

var xmlHttp = null;
xmlHttp     = new XMLHttpRequest();

xmlHttp.open( "GET", "/path/to/resource", false );
xmlHttp.send( null );

var data    = xmlHttp.responseText;