Dave's Brain

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); }

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.