Hi all,
I have the following file loaded by calling $.ajax
<div>This html is loaded dynamically
<script>
alert('Script executed from the loaded sample');
</script>
</div>
The script executes fine and the callback from $.ajax works. My issue
is that I would like the loaded script to attach to the object that
loaded it. I modified the callback as follows;
var self = this;
$.ajax({url: urlToLoad, dataType: 'html', success: function(data)
{ self.ContentReceived(data,self); } });
Which means in my callback I can find the object that it relates to,
but the callback occurs after the script has been executed.
Does anyone know a safe way of injecting context into the loaded
script? I could somehow set a variable that is picked up by the loaded
script but then I might have issues with multiple divs loading and
resetting this variable. Alternatively if the script exists within the
dom I might be able to shimmy up the hierarchy and find the div that
links to my object. But I'm not sure if this is even possible (I think
the script is executed globally, not within a DOM container).
Some hints on this would be greatly appreciated,
Regards
Ryan