linein designs

05 Jun, 2009

Run Javascript Code After an AJAX Request

Posted by: john In: javascript|php|programing

Earlier this week I had an interesting problem. I needed to have some javascript code run from within the page being called via AJAX. The javascript relied on the values being set in the page being called so it could not be setup on the page before hand. It had to be called afterward.

It basically came down to having to eval() the XMLHttpRequest data being sent. But thanks to developersnippets.com they wrote a very helpful article that fixes the issues I was having.

view demo | download files

Below is an explanation of the files included in the demo. We first need to make a generic page that has a single link that when clicked loads a separate page through an AJAX request.

// index.php

some content that is here when the page loads change div

Next we need to create the page that will be loaded via the AJAX request. Now the key here is that the page being loaded has Javascript that needs to be ran. So for our example we will launch a simple alert() commend that will show us a message along with a passed $_GET variable.

// load_page.php

Page has been succesfully changed []

change div

And that’s it for the very basic example of how you can use this. (not practical but should give you the concept) Please leave a comment below if you have any questions or need any help with this.

Similar Posts:

1 Comment »

Comment by Alfonso

Your code helped me a lot. Thank you

 
Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.

Trackback responses to this post


  • john: There's no easy way to stop it within the InnerFade plugin, but you could just erase all the list items after you've cycled through them using jQuery.
  • Steven: Rachid, did you find an answer? Is there a way to stop by a picture at the end? Can anyone help? Thanks in advance!
  • htc smartphone: WP togo is going to be a great little example of just what kind of super-power these droids will offer like the htc aria and other htc mobile phones l


Please Support Our Friends

Send emails with ease on this SMTP server by JangoSmtp.com.

Banner

About

My name is John Veldboom and have been in design and web programing for just over 8 years now. Started off as a hobby in high school but it has developed into a full time job now. I always tell people that if I wasn't doing this at work each day, I would be at home doing it for free. I love it!

Please visit the contact page to drop me a message.