I have a small problem which I can’t seem to find a solution to. The problem is that the following code works in FF but doesn’t in Safari. Probably it is a rookie mistake, but I have been struggling now for two days and it is really getting on my nerves.
<script type="text/javascript">
var settings = functionToReadSettings();
document.observe('dom:loaded', function () {
functionToInit(settings);
});
</script>
The error I get in Safari is in functionToInit. It says that settings in undefined. I tried changing the places – both the settings definition and the call to functionToInit to be in the dom:loaded and both to be outside of it, but then it doesn’t work in FF also.
Any help will be greatly appreciated.
Edit: Here is the functionToReadSettings :
functionToReadSettings: function () {
new Ajax.Request('readSettings.php', {
method:'get',
onSuccess: function(transport){
settings = transport.responseText.evalJSON(true);
}
});
return settings;
}
Well, syncrhonisation isn’t trivial task in js.
I don’t know, whether such features are implemented in prototype, but there’s another interesting library for such things:
http://onilabs.com/presentations/OSCON2010/par-fork-join.html