AJaX for weblogs

原创 2005年05月25日 20:36:00

转:Ajax  for  weblogs

The Asynchronous JavaScript + XML (AJaX) solution is one that can bring happiness and bliss to web designers and web developers alike. However, as with many whiz-bang solutions caution is advised. Google uses it to great effect but personally I think they take it a bit too far. If a page change so much that its context changes then it have switched to a new URI. People often bookmark specific content that’s within a specific context. As soon as this is no longer true it maybe a clue that you’ve gone to far.

The first thing I notice that the solutions is aimed at the heavier web applications. Not surprising. Web applications suffer from constraints that web clients impose on them. This solution gives them a way to check for dynamic content without reloading the current page.

So what does it do? 

Well it’s very simple. It uses Javascript to get data from a remote source and then loads that into a specified target. Whatever content you like to wherever you like on the page.
Jesse James Garrett of Adaptive Path has written an essay that covers the basics and provides more information on AJaX.

But lets get this sucker running, that’s the fun bit. And it’s pretty easy.

Step 1

Check if your web client can actually handle the http requests. We’ll need to use a Javascipt to do this.

var ajax=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
ajax = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
ajax = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
ajax = false;
@end @*/
if (!ajax && typeof XMLHttpRequest!=’undefined’) {
ajax = new XMLHttpRequest();

Step 2

Add the script that will pick up your data. In this case I’m not picking up XML data. But the weblog of your choice and in my case it’s ExpressionEngine will return the xHTML Which in turn will be inserted via the javascript innerHTML methode.

function getMyHTML(serverPage, objID) {
if((serverPage.indexOf("http://www.yourdomain.com/")!=0)) return;
var obj = document.getElementById(objID);
ajax.open("GET", serverPage);
ajax.onreadystatechange = function() {
if (ajax.readyState == 4 && ajax.status == 200) {
obj.innerHTML = ajax.responseText;

Step 3

The page that will display the dynamic content will need a placeholder element (tag) with a unique ID. The ID attribute will be used in the second script as a reference point to allow for insertion of the new dynamic content.

<title>AJaX test</title>
<body onload="getMyHTML(’serverpage.php’,’placeholder’)">
<div id="placeholder">
<p>The ‘getMyHTML’ script will overwrite
this paragraph.</p>

This URI in the ‘onload’ is the one which will generate the content.

Step 4

The dynamic bit is parsed by the engine of your choice like; Moveable Type, Expression Engine, Word Press etc. Of course you can use any other method of collecting content form a database.

In Expression Engine I’m calling a template that collects the data for my calendar. The whole calendar is outputted as HTML and inserted via the script.

Lets say the URI is ‘http://www.yourdomain.com/tempate/pageid/’
This could in fact be a PHP file or any other serverside script solution. The page only needs to return html. Here is an example in PHP.

echo '<p>this is a php echo text</p>';

And that’s about it. It’s all pretty old school but there you have it.


 cedrics weblog ( Thoughts on J2EE, Java, AOP and software development in general. )http://www.beust...
  • hitgnu
  • hitgnu
  • 2004年11月10日 09:21
  • 1034

nginx手记 location 配置及匹配规则

语法规则: location [=|~|~*|^~] /uri/ { … } = 表示精确匹配,这个优先级也是最高的 ^~ 表示 uri 以某个常规字符串开头,理解为匹配 url 路径即可...
  • SakuraLLj
  • SakuraLLj
  • 2016年07月20日 16:07
  • 521

Integrating Weblogs and Wikis

来源:http://www.pycs.net/users/0000177/categories/blogtools/ As part of a knowledge management e...
  • yuanqingfei
  • yuanqingfei
  • 2004年07月14日 13:46
  • 860


ajax简介 AJAX即“Asynchronous Javascript And XML”(异步JavaScript和XML),是指一种创建交互式网页应用的网页开发技术。Ajax不是一种新的编程...
  • u013766533
  • u013766533
  • 2016年08月25日 14:53
  • 4246


  • cat_pp
  • cat_pp
  • 2016年12月26日 17:13
  • 6460


出处:http://www.cnblogs.com/tylerdonet/p/3520862.html 1.url:  要求为String类型的参数,(默认为当前页地址)发送请求的...
  • qin_jian_bo
  • qin_jian_bo
  • 2016年03月05日 17:24
  • 14230


  • yiifaa
  • yiifaa
  • 2016年11月27日 11:11
  • 1685


header('content-type:text/html;charset=utf-8'); $op = isset($_POST['op']) ? $_POST['op'] : ''; ...
  • wlzx120
  • wlzx120
  • 2017年06月21日 17:05
  • 4127


无刷新求和示例    var xmlHttp;    function createXMLHttpRequest()    {        if(window.ActiveXObject)     ...
  • beniao277
  • beniao277
  • 2007年08月24日 20:34
  • 1269


$.ajax({ type:"POST", url: //你的请求程序页面随便啦 async:false,//同步:意思是当有返回值以后才会进行后面的js程序。 dat...
  • xyw591238
  • xyw591238
  • 2016年05月18日 10:27
  • 44085
您举报文章:AJaX for weblogs