Jump to content

innerHTML problem


JJohnsenDK

Recommended Posts

Hey

 

Im having some problems with my script:

 

http://www.jjwebsites.dk/home.php?site=calendar_test

 

When i press the next month or year button the whole page loads again into the first page.

Diffecult to explain but test it out at the link, when you will learn was it is about.

 

Here is the ajax script im using:

 


<script language="javascript">

function createQCObject() { 
   var req; 
   if(window.XMLHttpRequest){ 
      // Firefox, Safari, Opera... 
      req = new XMLHttpRequest(); 
   } else if(window.ActiveXObject) { 
      // Internet Explorer 5+ 
      req = new ActiveXObject("Microsoft.XMLHTTP"); 
   } else { 
      alert('Problem creating the XMLHttpRequest object'); 
   } 
   return req; 
} 

// Make the XMLHttpRequest object 
var http = createQCObject(); 

function displayQCalendar(m,y) {
var ran_no=(Math.round((Math.random()*9999))); 
http.open('get', '<?= $ajaxPath; ?>&m='+m+'&y='+y+'&ran='+ran_no);
   	http.onreadystatechange = function() {
	if(http.readyState == 4 && http.status == 200) { 
      		var response = http.responseText;
      		if(response) { 
			document.getElementById("quickCalender").innerHTML = http.responseText; 
      		} 
   		} 
} 
   	http.send(null); 
}
</script>

Link to comment
Share on other sites

The reason you are getting the entire content of the page is because your script it returning the entire HTML of the web site. If you change your home.php script to only return the calendar portion of the site when such request is made, then it would be working as you expect it to be. You can do that is various ways. One way is to move the output of the calendar itself into a function. Then, is we only want to output the calendar, output it then exit. Otherwise, continue with the declaration of the page. An example of such way:

 

<?php
// Function to display calendar
function displayMyCalendar() { ... }

// See if we only want to output the calendar
if($_GET['action'] == 'DisplayOnlyCalendar') {
    displayMyCalendar();
    exit();
}

// Output entire page since since we don't need to only display calendar
?>
<html>
...
<?php displayMyCalendar(); ?>
...
</html>

 

Your JavaScript then can stay pretty much as is.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.