prototype 好用的ajax框架

prototype 是一个轻型的ajax框架,但是不限于ajax,还包括对DOM的操作、对JSON操作的封装。是快速开发web应用的一种选择。
下面是一个使用了ajax的例子:
<script type="text/javascript">
function getwinfo(){
function onSuccess(request)
{
parseResults(request); //处理返回的天气信息
}

function onFailure(request){
$("result").innerHTML = request.responseText ;
}

var ajax = new Ajax.Request(
"http://weather.online.tj.cn/weather.asp",
{
method: 'get',
parameters:{areaid: 5} ,
onSuccess: onSuccess,
onFailure:onFailure
}
);

//处理返回的天气信息
function parseResults(request)
{
var myDocument = request.responseXML;
var xmlWeathers = myDocument.getElementsByTagName("weather"); //xml中所有记录的数组
var str = "";
str += xmlWeathers[2].getElementsByTagName("describe")[0].firstChild.nodeValue+" ";
str +="<font class='wendu'>"+ xmlWeathers[2].getElementsByTagName("tempA")[0].firstChild.nodeValue+"~";
str += xmlWeathers[2].getElementsByTagName("tempB")[0].firstChild.nodeValue+"</font> ";
$("weatherinfo").innerHTML = str;
}
}
</script>
</head>

<body onload="getwinfo()">
<div id="result">
<div id="weatherinfo" align="center" style="cursor:pointer;" onclick="window.open('http://weather.online.tj.cn')"></div>
</div>

可以看到ajax的请求已经被封装起来了。并且无需编码去判断返回状态了。
对DOM的操作也简化为$("xxx")的形式。
prototype 最新版是1.6。
prototype 可从这里下载:
http://www.prototypejs.org/download
详细的使用说明可以从这里下载:
http://www.prototypejs.org/learn
中文版的文档在csdn的这里:文档是1.5版本的。1.6版文档尚未公布。
http://download.csdn.net/source/350170

你可能感兴趣的:(prototype)