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:

Comments »

No comments yet.

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



Please Support Our Sponsors

A Payday advance can be a great way to get back on track.

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.