Dave's Brain

Browse - programming tips - jquery blocking get

Date: 2011sep18
Product: jQuery
Language: javaScript


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);
}
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, 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.
Advertisements: