Re: Re: jQuery .get and .ajax functions
By: Trash80 to Nightfox on Mon Feb 21 2011 17:47:18
Post your code (the one that isn't working for you).
Here it is:
// Loads a page in a div.
function loadPageInDiv(pFilename, pDivName) {
// Load the new file in the specified div.
$.get(pFilename, {}, function(responseText){
$("#" + pDivName).html(responseText);
});
}
Nightfox
---
þ Synchronet þ Digital Distortion BBS: digdist.bbsindex.com
/////////////////////////////////
this is what i use for my radio station
this code will reload a div every 10 secs.
if you want a link click version to load content into a div let me know.
//Create a .js file call it Ajax.js paste this code into it and save it. //Ajax.js
function Ajax(){
var xmlHttp;
try{
xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari
}
catch (e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
}
catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
alert("No AJAX!?");
return false;
}
}
}
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
document.getElementById('myDiv').innerHTML=xmlHttp.responseText; //The DIV ID that will hold the content
setTimeout('Ajax()',10000);
}
}
xmlHttp.open("GET","SOMEPAGE.HTML",true); // The Page to reload. xmlHttp.send(null);
}
//This sets the reload timer
window.onload=function(){
setTimeout('Ajax()',10000); //Reloads every 10 Secs.
}
//Example HTML document
<html>
<head>
<title> ... </title>
</head>
<body>
<!-- THIS does NOT have to be in the <head> section -->
<script language="javascript" type="text/javascript" src="path_to/ajax.js"> </script>
<!-- the div to be used -->
<div id="myDiv">
... DIV CONTENT GOES HERE ...
</div>
</body>
</html>
this is a very simple way of reloading a div using ajax.
---
þ Synchronet þ Octane BBS