Archive for the ‘Web Development’ Category
Simple Ajax based on Prototype Framework
Prototype is one of the most commonly used ajax framework in web2.0. Here is a very simple example to make a ajax page loading in the HTML.
First, you need to have the prototype framework, you can download here, or you can use the included one in the example zip file.
I wrapped the ajax page loading function in a javascript function, so we can reuse this function more easily, here is the javascript code:
function loadPage(pageURL, displayID, queryStr) {
var url = encodeURIComponent(pageURL);
var params = '';
if (queryStr != undefined)
params = queryStr;
new Ajax.Request(url, {
method: 'get', parameters: params,
onSuccess: function(transport) {
if(transport.responseText.length > 0){
document.getElementById(displayID).innerHTML=transport.responseText;
}}});
}
You need to pass 3 parameters for this function:
- pageURL - the page url which you want to load, without the HTML and BODY tag
- displayID - the div id which the result will be displayed
- queryStr - name and value pair for dynamic page, which is optional
And you need to define the display div in the HTML as follow:
<div id="display_body"> </div><br />
Now, you can simply use this javascript to load a page by ajax:
<a href="javascript:loadPage('hello-world.html', 'display_body')">Load Hello World Page</a>
And here is the example source in zip format:
Download Here
Feel free to give any comments for us, thanks.
6 must-have Wordpress plugins
Wordpress blog is very popular nowaday, we use wordpress in this development blog. We would like to introduce some must-have plugin for wordpress which make our job easier.
Here is a list of plugins:
- All in One SEO pack - help you do all SEO for your blog, like generate all title and meta tag automatically for you.
- Google Analyticator - everyone use Google Analytics now, this plugin make us more easy to use it on your wordpress.
- Google XML Sitemaps - another great tool to help you generate sitemap which help search engine to better understand your site.
- Sociable - one plugin for all social bookmarking sites, enable user to submit your posts or pages to their favourite bookmark.
- Similar Posts - display similar posts in your sidebar, you need to have Post-Plugin Library installed
- wp-cache - cache your dynamic posts or pages, make wordpress more efficent in loading, you may try to use wp-super-cache
Please let me know if you have more plugin to introduce to others, thanks.
Enjoy your wordpress blog.
Get your Sign Up Referer by PHP
Thanks to Google Analytics that help us on website traffic tracking. But for some reason we still need to track some specific statistics, like the referer of the user when user do a specific action, for a example, sign up on your website.
By using session in PHP, we can easily get the referer no matter which page the user is coming. Here is the PHP source code:
session_start();
if (empty($_SESSION[_referer'])) {
$host = parse_url($_SERVER['HTTP_REFERER'],PHP_URL_HOST);
if (empty($host)) {
$_SESSION['_referer'] = 'DIRECT';
} else {
$_SESSION['_referer'] = $host;
}
}
$referer = $_SESSION['_referer'];
And we can store the referer in the database or other tracking suit if we need.
You can download the php file and simply include it in your php header.
How to use:
1. Download the php source file and rename to .php extension
2. Include the php file in your php source or in your generic header file
3. Now you can just use the $referer to get the referer host information
include '/path/to/referer.php'; echo $referer;
Enjoy!