封装一个简单的Ajax函数
/**
* Ajax操作函数
*
* @param url -- 服务器端页面地址
* @param param -- 参数,类似 'user=123&id=100'
* @param method -- 请求服务器端的方法,Get和Post两种,默认是GET
* @param response -- 是否获取服务器端返回的结果,默认是true
*/
function ajax( url, param, method, response ){
//set default value
param = typeof(param)=='undefined' ? '' : param;
method = typeof(method)=='undefined' ? 'GET' : method;
response = typeof(response)=='undefined' ? true : response;
//get ajax object
var ajax = null;
try {
ajax = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
ajax = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
ajax = null;
}
}
if (!ajax && typeof XMLHttpRequest!='undefined'){
ajax = new XMLHttpRequest();
}
if (!ajax){
alert("Get ajax object failed");
return false;
}
//send http request
var res = '';
if (method != 'GET'){
method = 'POST';
}
if (method == 'GET'){
ajax.open('GET', url + param, true);
ajax.onreadystatechange = function(){
if (ajax.readyState==4 && ajax.status==200){
res = ajax.responseText;
}
}
ajax.send(null);
}
if (method == "POST"){
ajax.open("POST", url, true);
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
ajax.send(param);
ajax.onreadystatechange = function() {
if (ajax.readyState==4 && ajax.status==200) {
res = ajax.responseText;
}
}
}
if (response){
return res;
}
return null;
}
相关文档:
Download board.zip - 39.6 KB - Old Version
Download board_2008.zip - 55.03 KB - Latest VS 2008 Version
Introduction
This is an AJAX based WhiteBoard application. Typically unlike their desktop based counterparts, web applications need to be designed to use optimal ......
function createXMLHttpRequest() { // 创建XMLHTTPREQUEST的标准函数.兼容各浏览器.
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (wind ......
今天的话题是如何改进自己网站的界面或提高网站的视觉体验,从而让用户记忆犹新。
我们有三种主要的方法(从难到易):自己动手写脚本;使用类似于jQuery和mooTools的JavaScript框架(可以让编写代码变得更容易些);使用能工作于现有的JavaScript框架下的提前预置好的脚本或那种从头开始开发的创建者。这篇文章适合那 ......
1.到http://ajaxcontroltoolkit.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=33804
下载AJAX Control Toolkit - Binary
2.解压到C:\Program Files\Microsoft.NET\ADOMD.NET\90
3.visual studio 新建一网站,双击default.aspx
4.打开工具箱,右击新建一选项卡,明名为Ajax Control Toolkit
5.右击Ajax Contr ......
Ajax框架 jQuery
jQuery是一款免费且开放源代码的JavaScript代码库,由John Resig创建。授权协议为GPL和MIT许可证双协议。示例代码: $("p.neat").addClass("ohmy").show("slow"); 特点轻量级经GZip压缩后传输的代码文件仅14KB,未经压缩传送的代码文件仅26KB。 jQuery 1.26版时: 档案档案行数档案Size 备注 jquery-1.2 ......