分享
 
 
 

AJaX for weblogs

王朝java/jsp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

转: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;

}

}

ajax.send(null);

}

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.

<html>

<head>

<title>AJaX test</title>

</head>

<body onload="getMyHTML(’serverpage.php’,’placeholder’)">

<div id="placeholder">

<p>The ‘getMyHTML’ script will overwrite

this paragraph.</p>

</div>

</body>

</html> 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.

<?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.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有