|
An easy Ajax fix? Please help!!!!
Basically, what I want to happen is I want to have an empty div populate with a table displaying live statistics. I have the code written for that and basically want to call the .php page to refresh inside this div. Here is what I have:
_________________________________________________
<script language="javascript" type="text/javascript">
var url = location.href;
window.onload = setInterval('ajaxFunction();',10000);
<!--
//Browser Support Code
function ajaxFunction(){
var ajaxRequest;
try{
// Opera, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// IE
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Please Try Your Request Again Later");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('ajaxDiv');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
ajaxRequest.open("POST", 'ajaxDiv', true);
ajaxRequest.send(null);
}
//-->
</script>
<div id="ajaxDiv">
</div>
______________________________________________________
So basically I want to inject my .php file inside the div and show its contents. Currently it injects the index page after the first 10 seconds. What would be great is if I could take the current URL and strip it of the file reference and replace it with the .php file. i.e.:
www.url.com.../admin/page.html
to
www.url.com.../admin/file.php
and then point the div to repopulate with the php url inside the div. It (www.url.com...) needs to be dynamic because this is on an enterprise app. What do you guys have?
|