Dear coders,
I'm facing a problem and after few research I found that many ppl were looking around for the same solution, hope someone more expert than me could give a good help.
I created an AJAX function that i.e. on click does a request to a server and show into a specified tag the results (well until here is something eveyone would do with AJAX)... the point is that the result is something like the this:
i.e.
[HTML]<!-- this is the span tag where I'm going to wrap the ajax result -->
<span name="script2ex e" id="script2exe" >
some HTML...
<script type="text/javascript" language="javas cript">
some JAVASCRIPT...
</script>
some HTML...
</span>[/HTML]
As we would expect the Javascript that will be received with the "innerHTML" will be not executed...
well as a beginner it was quite strange to me, but I understood that we need to weap the Javascript into a tag with id... than call it and eval whats wrapped in... I will show you what I did, and I tryed few different ways, but nothing!
[CODE=javascript]// this is the callback function to retrieve the ajax request
function alertContentsIn it(http_request , tag_target) {
if (http_request.r eadyState == 4) {
if (http_request.s tatus == 200) {
result = http_request.re sponseText;
// with this I get all the response that a PHP page build
document.getEle mentById(tag_ta rget).innerHTML = result;
// with this following two row, I try to get the script and execute it
script2exe = document.getEle mentById("scrip t2exe");
eval(script2exe .getElementsByT agName("script" ).innerHTML);
} else {
alert(\'There was a problem...\');
}
}
}[/CODE]
When I execute my page, nothing happen... the ajax result is loaded correctly, looking to the source code, I can see also the javascript well placed and correct builded (cos i tested it separately) but the eval... seems to be not correct (no errors received from the browser!)
thank you in advance for any help.
I'm facing a problem and after few research I found that many ppl were looking around for the same solution, hope someone more expert than me could give a good help.
I created an AJAX function that i.e. on click does a request to a server and show into a specified tag the results (well until here is something eveyone would do with AJAX)... the point is that the result is something like the this:
i.e.
[HTML]<!-- this is the span tag where I'm going to wrap the ajax result -->
<span name="script2ex e" id="script2exe" >
some HTML...
<script type="text/javascript" language="javas cript">
some JAVASCRIPT...
</script>
some HTML...
</span>[/HTML]
As we would expect the Javascript that will be received with the "innerHTML" will be not executed...
well as a beginner it was quite strange to me, but I understood that we need to weap the Javascript into a tag with id... than call it and eval whats wrapped in... I will show you what I did, and I tryed few different ways, but nothing!
[CODE=javascript]// this is the callback function to retrieve the ajax request
function alertContentsIn it(http_request , tag_target) {
if (http_request.r eadyState == 4) {
if (http_request.s tatus == 200) {
result = http_request.re sponseText;
// with this I get all the response that a PHP page build
document.getEle mentById(tag_ta rget).innerHTML = result;
// with this following two row, I try to get the script and execute it
script2exe = document.getEle mentById("scrip t2exe");
eval(script2exe .getElementsByT agName("script" ).innerHTML);
} else {
alert(\'There was a problem...\');
}
}
}[/CODE]
When I execute my page, nothing happen... the ajax result is loaded correctly, looking to the source code, I can see also the javascript well placed and correct builded (cos i tested it separately) but the eval... seems to be not correct (no errors received from the browser!)
thank you in advance for any help.
Comment