JJohnsenDK Posted December 30, 2007 Share Posted December 30, 2007 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> Quote Link to comment Share on other sites More sharing options...
mainewoods Posted December 31, 2007 Share Posted December 31, 2007 whan you call an ajax routine, always return false so that the default action(like following a link) does not take palce: http.send(null); return false; } Quote Link to comment Share on other sites More sharing options...
duclet Posted January 1, 2008 Share Posted January 1, 2008 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.