Jump to content
xisto Community
Sign in to follow this  
Pankyy

Mootools 1.2 Ajax Refresh

Recommended Posts

I think this might count as a tutorial, and is ok in this forum because it's to contribute to web developers (if something is wrong tell me). I was just using this and I think this could as well help others posting it and explaining a little the structure. For those who don't know, Mootools is a built-in .js made to make easier using AJAX with javascript as well. You can download the necessary version here.

First, you must put this in the web:

<script type="text/javascript" src="js/mootools.js"></script>

The bolded part (js/mootols.js) is the directory of the script I asked for you to download up there. Change if necessary.

<script language="javascript">var request = new Request({	url: 'web_to_open.php',	method: 'get',	update: 'refresh-me',	onComplete: function(response) {		$('divid').set('html',response);	}})var doRefresh = function() {	request.send();};doRefresh.periodical(5000);</script>

The first bolded part (web_to_open.php) is the url of the web you want the AJAX to visit, you can obviously change it to the one you want, as well add GET parameters (web.php?id=X).

The second bolded part (divid) is, as the name indicates, the div id you want to replace for the output of the link. I marked the html part to let you know that the output is gonna serve as HTML. If it has html tags, the page will use them. If you replace it for 'text', then html tags won't be used, but displayed to user.

The last part bolded, the number, is the milliseconds it will need to refresh the page. 5000 is 5 seconds (1000x1s is the pattern).

<div id='divid'></div>

Last, but not least important, the html code. The divid is once more marked as it is necessary for it to match the other one to make this work.

I've read that there are some people that don't like Mootools, that maybe it isn't too efficient. I don't know, personally, I don't like too much javascript and this makes it so much easier, with a few lines, that I don't really care.

Post if you have any problems! (I think I didn't forget anything)
Edited by Pankyy (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.