ajax封装:
A.Ajax.doAjax = function (vo)
{
var url = vo.url, //url
onsuccess = vo.onsuccess, //成功回调函数
onfailure = vo.onfailure, //成功回调函数
fdata = vo.params, //传递参数
method = vo.method, //post get
sdata = vo.sdata, //post数据
asyn = vo.asyn; //是否异步
fdata = (fdata === undefined)? null: fdata;
method = method || "GET";
sdata = (sdata === undefined)? null: sdata;
asyn = (asyn === undefined)? true: asyn;
onfailure = (onfailure === undefined)? null: onfailure;
var X = new bajax_object();
if(asyn){
X.onreadystatechange = function(){
if (X.readyState == 4) {
if((X.status >= 200 && X.status < 300) || X.status == 0){
// if()
onsuccess(X, fdata);
// };
}else{
if(onfailure != null){
onfailure(X,fdata);
}
return;
};
}
};
}
X.open(method, url, asyn);
X.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
X.send(fdata);
if(asyn) return X;
else callback(X, fdata);
}
// 兼容IE与其它浏览器(From Sajax.php v0.12)
var bajax_object = function()
{
var aj;
var _msxmlhttp = new Array(
'Msxml2.XMLHTTP.5.0',
'Msxml2.XMLHTTP.4.0',
'Msxml2.XMLHTTP.3.0',
'Msxml2.XMLHTTP',
'Microsoft.XMLHTTP');
for(var i = 0; i < _msxmlhttp.length; i++) {
try {
if(aj = new ActiveXObject(_msxmlhttp[i])) break;
} catch (e) {
aj = null;
}
}
if(!aj && typeof XMLHttpRequest != "undefined")
aj = new XMLHttpRequest();
if(!aj)
alert("Could not create connection object.");
return aj;
}
AUI.add('aui-notification', function(A) {
A.namespace("Notification");
var Notification,
Note,
_proVO = {},
_funMap = {};
Notification = function (config) {
Notification.superclass.constructor.apply( this, arguments );
};
Note = A.Notification;
var spy = function(obj){
var arr = [];
if(obj != null){
for(var itm in obj){
var value = obj[itm];
if(typeof value == "function"){
value = "function(){...}";
}else if(typeof value == "object" && value != null){
value = "{...}";
}
arr.push(itm + "/t= " + value);
}
}
return arr.join("/r/n");
}
/*
* 说明:注册通知
*
*/
var extend = function(destination, source) {
for (var property in source)
destination[property] = source[property];
return destination;
}
Note.register = function(id,name,porName){
if(_proVO[porName] == null){
_proVO[porName] = {};
}
if(_proVO[porName][name] == null){
_proVO[porName][name] = {};
}
if (_proVO[porName][name].id == null)
{
_proVO[porName][name].id = [];
}
_proVO[porName][name].id.push(id);
}
/*
* 说明:发送通知
*
*/
Note.send = function(name, vo, porName){
//调试时用
var proVO = _proVO[porName];
if(_proVO[porName] == null){
alert("模板未加载");
return ;
}
var noteMap = _proVO[porName][name];
if(_proVO[porName][name] == null){
alert("通知名未定义");
return ;
}
if (_proVO[porName][name].vo == null)
{
_proVO[porName][name].vo = {}
}
extend(_proVO[porName][name].vo,vo);
}
//根据组件名通知名返回id
Note.getVO = function(name, porName){
var proVO = _proVO[porName];
if(proVO == null){
alert("模板为加载");
return ;
}
var noteMap = proVO[name];
if(noteMap == null){
alert("通知名未定义");
return ;
}
return noteMap.vo;
}
//获取页面的回调参数集合
Note.getFuns = function(obj,porName){
if(_funMap[porName] == null){
_funMap[porName] = {};
}
extend(_funMap[porName], obj);
}
//处理回调方法
Note.handler = function(funName,porName){
if(_funMap[porName] == null){
alert("模板为加载")
return ;
}
if(_funMap[porName][funName] == null){
alert("回调函数未定义")
return ;
}
_funMap[porName][funName]();
}
Note.remove = function(porName){
if(_funMap[porName] == null){
return ;
}
delete _funMap[porName];
}
}, '1.0.1');
前台通知组件,用于组件之间数据存储,适用于模块式开发