Ajax Talk - Asynchronous javascript and xml discussion board
 FAQ   Search    Usergroups      Register   Profile   Check your messages   Log in 
Signup now to enjoy a range of free membership advantages !!
Ajax Talk - Moderators Wanted
Javascript execution after an AJAX response

 
Post new topic   Reply to topic    Ajaxtalk.com Forum Index -> AJAX general discussion
View previous topic :: View next topic  
Author Message
pablos_uk
New one
New one


Joined: 04 Aug 2008
Posts: 1

PostPosted: Mon Aug 04, 2008 9:29 am    Post subject: Javascript execution after an AJAX response Reply with quote

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.

Code:
<!-- this is the span tag where I'm going to wrap the ajax result -->
<span name="script2exe" id="script2exe">
some HTML...
<script type="text/javascript" language="javascript">
some JAVASCRIPT...
</script>
some HTML...
</span>


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:
//  this is the callback function to retrieve the ajax request

function alertContentsInit(http_request, tag_target) {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
result = http_request.responseText;
//  with this I get all the response that a PHP page build
document.getElementById(tag_target).innerHTML = result;

//  with this following two row, I try to get the script and execute it
script2exe = document.getElementById("script2exe");
eval(script2exe.getElementsByTagName("script").innerHTML);
} else {
alert(\'There was a problem...\');
}
}
}



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.
_________________
Pablos UK
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Ajaxtalk.com Forum Index -> AJAX general discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
 Advertisements
 XML & Copyright Notice 
    


Powered by phpBB © 2001, 2005 phpBB Group

What is according to Wikipedia: Ajax Web2.0 XML E4X


Link to our site:

  


del.icio.us digg spurl wists simpy newsvine blinklist furl blogmarks yahoo! myweb smarking ma.gnolia segnalo reddit fark technorati cosmos


Normal Bookmark


Partner Button Links:
Codecrunch.com: Webmaster Tutorials    One Ajax


Partner Text Links:
quomon | web20log | ajaxmatters | tableless | 456bereastreet | music charts | gift ideas | competitions | free xbox 360 | link trade ?


Credits:
it consultancy & project management lead generation zoekmachine optimalisatie steal these buttons seo expert