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.
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.phpsome 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:
- jQuery Image Gallery with Transitions and Navigation
- jQuery Loading – Display Images or Text Until Script is Finished
- Fade In and Out Images from a Single Directory Using jQuery (with plugin)
- Alternate Background Colors Using PHP
- PHP Font Preview Function (text to image)
Related Posts:

No comments yet.