简单实用的ajax脚本
文件名:ajax.js
/**
* 取得当前页面的url
* 可以在调用ajax_query前修改
**/
var url = location.href.substr(0, location.href.length-location.search.length);
/**
* 给Function对象添加一个取得函数名的方法
**/
Function.prototype.Name = function() {
var s = Function.prototype.Name.caller.toString();
return s.split(/[\r\n]+/)[0].replace(/function\s+(\w+).+/g, '$1');
}
/**
* 函数 $
* 功能 获取dhtml对象
* 参数 e 待查找的对象id或name
* 返回 成功:对象 失败:null
*/
function $(e) {
var tag = document.getElementById(e);
if(tag) return tag;
tag = document.getElementsByName(e);
if(tag.tagName == undefined) return null;
return tag;
}
/**
* 函数 ajax_query
* 功能 向服务器发送指令,并处理返回数据
* 参数
* method 服务器端方法名
* tag 接受返回数据的dhml对象名,缺省时由服务器决定处理方式
* 其他 向服务器端传递的其他参数,可缺省
* 说明 虽然Msxml2.XMLHTTP有着比Microsoft.XMLHTTP更优秀的性能,但是在配置较低的
* 环境下并不能正常工作。当确认能够正常工作时,再删去注释
**/
function ajax_query(method, tag) {
//尝试创建XMLHTTP对象
var xmlhttp;
//// try {
//// xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
//// }catch(e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (oc) {
xmlhttp = null;
}
//// }
if(!xmlhttp && typeof XMLHttpRequest != "undefined") {
var xmlhttp = new XMLHttpRequest(); // Mozilla, Safari, ...
}
if(! xmlhttp) {
alert('错误! 缺少连接组件');
return;
}
if(arguments.length == 0) {
alert(Function.Name()+'至少需要一个方法名');
return;
}
var data =
相关文档:
刚开始学Ajax,看到很多网上的代码都用Get方法提交参数,Tomcat默认ISO编码实在是让人头痛,对付乱码我都是用过滤器做字符编码过滤的,Get方法过滤器监听不到,所以我一直喜欢使用Post方法,下面对Ajax Get和Post方法做一对比
GET:
view plaincopy to clipboardprint?
<mce:script type="text/javascript"><!- ......
在本节我准备只写上关于Ajax的说明,多数来自jQuery的帮助文档,所以不要放在首页。因为我觉得首页应该是要花费了时间和心思的作品。代码演示和jQuery Ajax 一些新的,将在下一次有空时讲述,这里就不讲了。时间已经0晨了。如果你举得有什么jQuery的疑问或者觉得Ajax该讲述那些内容的都可以跟我留 ......
页面代码:
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManage ......
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:updatepanel ID="UP" runat="server">
<ContentTemplate>
......
http://hi.baidu.com/cxzhang/blog/item/0166563892cc65fbb211c7b0.html.
http://topic.csdn.net/t/20030527/22/1842509.html
using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Reflection;
public class ToJson
{
/// <summary>
......