Basically I'm currently loading content into a div using ajax in the following manner:
Code:
<a href="#" onclick="makerequest('page.php', 'ajax_div'); return false;">Ajax Request </a>
The makerequest function takes in the requested page and the target div as it's parameters and looks like this:
Code:
// Create a boolean variable to check for a valid Internet Explorer instance.
var xmlhttp = false;
// Check if we are using IE.
try
{
// If the Javascript version is greater than 5.
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
// If not then use the older active x object.
try
{
// If we are using Internet Explorer.
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (E)
{
// We must be using a non-IE browser.
xmlhttp = false;
}
}
// If we are using a non-IE browser, create a javascript instance of the object.
if(!xmlhttp && typeof XMLHttpRequest != 'undefined')
{
xmlhttp = new XMLHttpRequest();
}
// Make Request Function.
function makerequest(serverPage, objID)
{
var obj = document.getElementById(objID);
obj.innerHTML = "<div align='center'><img src='/loading.gif' /></div>";
xmlhttp.open("GET", serverPage);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
obj.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(null);
}
So that works perfectly and the php page loads in the target div no problem. Now as you can imagine I am running into the problem with executing javascript inside of the loaded php page.
In this specific instance I have some form input elements that are loading using javascript, (relational lists).
Normally I just include this in the head of the document
Code:
<script language='JavaScript' type='text/javascript' src='/HDWRelationalList/RelationalList.js'></script>
<SCRIPT language='JavaScript' type='text/javascript'>
function LoadRelationalList(){
var RelationalList0 = new RelationalList(list1, 'list2', '/list1.xml', '/list2.xml');
}</SCRIPT>
The above of course doesn't work in content loaded via ajax. I'm not really against using prototype's built in ajax functions, I've just been using my own so maybe I should switch to get this to work?
Thanks for your help,
Chris
Bookmarks