Browse - Programming Tips - How can do I a blocking GET with jQuery?

Date: 2011sep18
Library: jQuery
Language: javaScript
Keywords: synchronous

Q.  How can do I a blocking GET with jQuery?

A.  Here are two functions that do just that:

function blockingGet1(url) { return $.ajax({ url: url, async: false }).responseText; } function blockingGet2(strUrl) { var strReturn = ''; $.ajax({ url:strUrl, success: function(html){strReturn = html;}, async:false }); return strReturn; } function exampleUse() { var stuff = blockingGet1('/data.txt'); alert(stuff); }