- 热门文章:
- · java编辑多语言的福音--推荐一个经典的多语言文件编辑的插件ResourceBundle Editor
- · 通过reflect中得到数组类型
- · Jbuilder快捷键
- · tomcat+mysql数据库的连接池配置
- · jfreechart 的java对象关系简释
- · [分享]eclipse 3.0 中jre设置的小错误导致在java文件中连接数据库失败
- · Refactoring Notes-Refactoring Methods(3)
- · ECLIPSE初学手记(1)
- · ECLIPSE初学手记(2)
- · IT人才风向标之java——java人才现状大调查结果出炉
- · Ajax: Web应用开发的一种新方法
- · JMX入门之StandardMBean HelloWord
上一篇:IntelliJ IDEA培训 >>
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.
相关文章:
- · 学习使用DispatchAction
- · Project_Mapping 我给大家解释一下
- · JNDI简介,jndi在tomcat中的配置,jdbc api简介,java连接数据库服务
- · SCWCD1.4的资料
- · [Eclipse笔记]Just for fun – 在Eclipse下编译和运行C#的代码
- · 升级到J2SE 5平台的5大理由
- · Optimizeit Thread Debugger概览
- · 一个过滤html输入字符的类
- · 在csdn上看到的怪问题
- · JAVA - IO包的学习引导文章(摘抄)
- · 新Java技术工具亮相游戏开发商大会
- · Quartz,企业级的计划/日程安排(job schedule)系统(1)-介绍
- · Netark FileManager 远程文件管理
- · 使用自定义标签,将结果集返回到jsp页面!(推荐方法)
- · 控制运行中的application进程实例的个数
- · 获取类的class文件的绝对路径
- · Smartupload和commons-fileupload介绍与比较
- · 理解finalize()-析构函数替代者
- · Thinking:Java中static、this、super、final用法
- · Bad Smells in Code
- · JDK1.5新特性一览
- · Sun重申一许可 并发布俩新许可
- · P2P流媒体为网络应用带来改变
- · 由于struts配置文件没有定义头文件引起的问题
- · 今日笔记系列之Log4J
- · eclipse下tanghan plugin连mssql实战
- · 小心重写方法,正确实现多态
- · 一些无聊的代码之一:JAVA中的日期计算
- · [Eclipse笔记]Eclipse项目3.1开发目标和进度
- · 关于Tomcat的并发处理能力
- · ANT 操控 ORACLE数据库实践
- · PHP和JAVA的XML-RPC中文问题解决办法
- · jasperreport中的demo学习
- · 《java与模式》----创建模式系列工厂模式、单态模式精讲
- · 《java与模式》读书笔记 ----模式设计的原则
- · 《java与模式》笔记-----抽象类和接口
- · 关于如何使用JdbcTemplate实现在WebLogic812,Oracle9i上的CLOB数据的写操作
- · Optimizeit Code Coverage概览
