I found a workaround, but maybe there's an issue with $.get in jquery
1.1.2 that messes with using it recursively, or some option I could set?
I replaced the $.get with this and it worked like a charm:
$.ajax({
type: 'GET',
url: filePath,
success: function(template){
templates[ fileName.split('.')[0] ] = template;
getTemplates();
}
});
- Jack
Jack Killpatrick wrote:
Losing some hair over this one.... maybe someone can help? I'm using
jquery 1.1.2 (and must use that rev). I have a list of html files
(snippets of html) that I want to fetch sequentially via a $.get and
store in a hash. I'm doing something like this, using while and
shift() to loop through the list (I don't need the array after it's
been looped through) and make a recursive call to the getTemplates
function:
var baseUrl = 'http://www.mydomain.com/snippets';
var fileList = ['discounts.html', 'categories.html', 'options.html',
'inventoryOptions.html', 'skuOptions.html'];
var templates = {};
function getTemplates(){
if (fileList.length > 0){
var fileName = fileList.shift(); // shrinks the queue
var filePath = baseUrl + '/' + fileName;
$.get( filePath, function(template){
templates[ fileName.split('.')[0] ] = template;
getTemplates(); // recursive call (works on 2nd call,
then dies)
});
}
}
}
The $.get works fine for the first file, but for the 2nd file it's url
gets "?prototype=%5Bobject%20Object%5D" appended to the end of it,
which *does* fetch the 2nd file, but then the code dies silently after
that. Example of the 2nd url:
http://www.mydomain.com/snippets/categories.html?prototype=%5Bobject%20Object%5D
Any ideas about what's happening and how to make it do what I want? I
don't really want to resort to an ajax queuing plugin if I can avoid it.
Thanks!
- Jack