Hi all
I have ran into a problem with Ajax which I hope you can answer.
First of all, this is my basic Ajax routine
1) I'm using the sack library (
http://twilightuniverse.com/resources/code/sack/)
2) I'm making a call to the server and get the answer back and stored in a response property of the js sack object, let's call it
ajax.response;
3) Then I'm inserting this content into a element on the page like this:
document.getElementById('m
yDiv').inn
erHTML = ajax.response;
Now, the problem arise in IE because it won't parse javascript content in the response.
So this is my solution....which almost works:
__evaluateJs : function(obj)
{
window.jsCode = new Array();
var scriptTags = obj.getElementsByTagName('
SCRIPT');
var head = document.getElementsByTagN
ame('HEAD'
)[0];
for(var no=0;no<scriptTags.length;
no++){
if (scriptTags[no].src){
var head = document.getElementsByTagN
ame("head"
)[0];
var scriptObj = document.createElement("sc
ript");
scriptObj.setAttribute("ty
pe", "text/javascript");
scriptObj.setAttribute("sr
c", scriptTags[no].src);
head.appendChild(scriptObj
);
}else{
var code = scriptTags[no].innerHTML;
window.jsCode[no] = code;
setTimeout('eval(window.js
Code[' + no + '])',100); // Has to wait because we want to make all objects part of the window object(global variables) instead of locale
}
}
}
I'm sending document.getElementById('m
yDiv') as a input to this method. This method parses the <script> tags inside the element and runs an eval() on the innerHTML of each of them.
This executes the javascript code.
But now comes the challenge: functions and variables inside that method are registered as member of the method where the eval() is executed. They become local variables instead of globals. I have tried to solve this by implementing a setTimeout( setTimeout('eval(window.js
Code[' + no + '])',100); ) , but that only seem to work in Firefox.
I have made an example here:
http://www.dhtmlgoodies.com/examples/ajax.htmlit includes the file
http://www.dhtmlgoodies.com/examples/ajax_include.htmlIf it works, a click on the link at the bottom should alert "20" (which it does in FF).
But IE says that "myObj is undefined".
I hope someone can help me with this problem.
Thanks a lot