var sUrlBase ='';
var sNamespace = 'http://www.hongzhao.com';
var sNoXmlHttp = 'The browser does not surport XMLHTTP.';
/* httpxml */
function XmlHttpRequest(){//new(-[1,]?XMLHttpRequest:ActiveXObject)("Microsoft.XMLHTTP")
var oXmlHttp = null;
if(window.XMLHttpRequest){
oXmlHttp = new XMLHttpRequest();
}else{
try{
oXmlHttp = new ActiveXObject('MSXML2.XMLHTTP.4.0');
}catch(e){
try{
oXmlHttp = new ActiveXObject('MSXML2.XMLHTTP.3.0');
}catch(e){
try{
oXmlHttp = new ActiveXObject('MSXML2.XMLHTTP.2.6');
}catch(e){
try{
oXmlHttp = new ActiveXObject('MSXML2.XMLHTTP');
}catch(e){
try{
oXmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
}catch(e){}
}
}
}
}
}
return oXmlHttp;
}
function HttpUrlCommand(url, sync, request){
var oXmlHttp = XmlHttpRequest(); //new (window.XMLHttpRequest || ActiveXObject)("Microsoft.XMLHTTP")
if(oXmlHttp == null){
alert(sNoXmlHttp);
return 'NULL';
}
var issync = !RemoteIsNull(sync);
var doc = RemoteIsNull(request) ? '' : request;
if(url.indexOf('?') == -1){
oXmlHttp.open('GET', url +'?token='+ token(), issync);
}else{
oXmlHttp.open('GET', url +'&token='+ token(), issync);
}
//oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
oXmlHttp.send(null);
if(issync){
oXmlHttp.onreadystatechange = readyStateChanged;
}else{
return oXmlHttp.responseText;
}
function token(){
var hex = new Array('0','1','2','3','4','5','6','7','8', '9','a','b','c','d','e','f');
var t = '';
for (var i = 0; i<32; i++){
t += hex[Math.floor(Math.random() * 16)];
}
return t.toUpperCase();
}
function readyStateChanged(){
if (oXmlHttp.readyState == 4)
{
if (oXmlHttp.status != 0)
{
var result = oXmlHttp.responseText;
sync(result);
oXmlHttp.abort();
}
}
}
}
function HttpUrlCommand2(url, sync, param){
var request=null;
var oXmlHttp = XmlHttpRequest(); //new (window.XMLHttpRequest || ActiveXObject)("Microsoft.XMLHTTP")
if(oXmlHttp == null){
alert(sNoXmlHttp);
return 'NULL';
}
var issync = !RemoteIsNull(sync);
var doc = RemoteIsNull(request) ? '' : request;
if(url.indexOf('?') == -1){
oXmlHttp.open('GET', url +'?token='+ token(), issync);
}else{
oXmlHttp.open('GET', url +'&token='+ token(), issync);
}
//oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
oXmlHttp.send(null);
if(issync){
oXmlHttp.onreadystatechange = readyStateChanged;
}else{
return oXmlHttp.responseText;
}
function token(){
var hex = new Array('0','1','2','3','4','5','6','7','8', '9','a','b','c','d','e','f');
var t = '';
for (var i = 0; i<32; i++){
t += hex[Math.floor(Math.random() * 16)];
}
return t.toUpperCase();
}
function readyStateChanged(){
if (oXmlHttp.readyState == 4)
{
if (oXmlHttp.status != 0)
{
sync(param);
oXmlHttp.abort();
}
}
}
}
function CreatLoadingLayer(o){
var layer = document.createElement('div');
layer.style.verticalAlign = 'middle';
layer.style.textAlign = 'center';
layer.style.background = 'url(/Global/images/system/loading.gif) no-repeat center';
layer.style.position='absolute';
var itop=(document.documentElement.clientHeight-o.clientHeight)/2+document.documentElement.scrollTop;
var ileft=(document.documentElement.clientWidth-o.clientWidth)/2+document.documentElement.scrollLeft;
//layer.style.left=ileft+'px';
layer.style.top=itop+'px';
var width = o.clientWidth;
var height = o.clientHeight-70;
if(width < 40){
var parent = o.parentNode;
width = parent.clientWidth;
if(width < 40){
width = 40;
}
}
if(height < 40){
height = 40;
}
if(width>40){width = width - 20;}
layer.style.width = width + 'px';
layer.style.height = height +'px';
//o.innerHTML = '';
o.appendChild(layer);
}
function CreatLoadingLayer2(o){
var layer = document.createElement('div');
layer.style.verticalAlign = 'middle';
layer.style.textAlign = 'center';
layer.style.background = 'url(/Global/images/system/loading.gif) no-repeat center';
var width = o.clientWidth;
var height = o.clientHeight;
if(width < 40){
var parent = o.parentNode;
width = parent.clientWidth;
if(width < 40){
width = 40;
}
}
if(height < 40){
height = 40;
}
if(width>40){width = width - 20;}
layer.style.width = width + 'px';
layer.style.height = height +'px';
o.innerHTML = '';
o.appendChild(layer);
}
function HttpAjax(loadurl, elem, request){
var o = document.getElementById(elem);
CreatLoadingLayer(o);
HttpUrlCommand(loadurl, http_callback, request);
function http_callback(res){
o.innerHTML = res;
}
}
function PageAjax(dourl, elem, regexp, request){
var o = document.getElementById(elem);
HttpUrlCommand(dourl);
CreatLoadingLayer(o);
HttpUrlCommand(window.location.pathname + window.location.search, page_callback, request);
function page_callback(res){
var re1;
if(regexp !=null && regexp!=''){
re1 = new RegExp(regexp, 'img');
}else{
re1 = new RegExp('<div\\sid="'+elem+'">([\\s\\S]+?)</div>', 'img');
}
if(re1.test(res) == true){
o.innerHTML = RegExp.$1;
}else{
o.innerHTML = 'Loading Data Error';
return;
}
}
}
//function LoadAjax(dourl,elem,regexp, request){
// var o = document.getElementById(elem);
// HttpUrlCommand(dourl);
// CreatLoadingLayer(o);
// HttpUrlCommand(window.location.pathname + window.location.search, page_callback, request);
//
// function page_callback(res){
// var re1;
// if(regexp !=null && regexp!=''){
// re1 = new RegExp(regexp, 'img');
// }else{
// re1 = new RegExp('<div\\sid="'+elem+'">([\\s\\S]+?)</div>', 'img');
// }
//
// if(re1.test(res) == true){
// o.innerHTML = RegExp.$1;
// }else{
// o.innerHTML = 'Loading Data Error';
// return;
// }
// }
//}
/* no edit below */
function RemoteCommand(sObject, sCommand)
{
this.Command = sCommand;
this.GetParameter = getParameter;
var sXmlDocumentStart = "";
var sXmlDocumentEnd = "";
var oXmlHttp = XmlHttpRequest();
if(oXmlHttp == null){
alert(sNoXmlHttp);
return 'NULL';
}
var aParameters = new Array();
var sUrl = sUrlBase + sObject + ".asmx";
alert(sUrl);
sXmlDocumentStart += "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
sXmlDocumentStart += "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">";
sXmlDocumentStart += "<soap:Body>";
sXmlDocumentStart += "<" + sCommand + " xmlns=\"" + sNamespace + "/\">";
sXmlDocumentEnd += "</" + sCommand + ">";
sXmlDocumentEnd += "</soap:Body>";
sXmlDocumentEnd += "</soap:Envelope>";
this.Execute = execute;
this.SetParameter = setParameter;
this.Abort = abort;
this.Command
function getParameter(sName)
{
var i = aParameters[sName];
if (!RemoteIsNull(i))
{
return aParameters[i];
}
return null;
}
function setParameter(sName, sValue)
{
var oParameter = (RemoteIsNull(sValue))? sName : new CommandParameter(sName, sValue);
if (!RemoteIsNull(aParameters[oParameter.Name]))
{
aParameters[aParameters[oParameter.Name]] = oParameter;
}
else
{
aParameters[oParameter.Name] = aParameters.length;
aParameters.push(oParameter);
}
}
function abort()
{
oXmlHttp.abort();
}
function execute(funAsyncCallbackFunction)
{
var sXmlDocument = sXmlDocumentStart;
if (oXmlHttp.readyState > 0 && oXmlHttp.readyState < 4)
{
abort();
}
for (var i = 0; i < aParameters.length; i++)
{
sXmlDocument += aParameters[i].GetXml();
}
sXmlDocument += sXmlDocumentEnd;
var async = !RemoteIsNull(funAsyncCallbackFunction);
if (async)
{
var oAsyncResultHandler = new AsyncResultHandler(this, oXmlHttp, funAsyncCallbackFunction);
oXmlHttp.onreadystatechange = oAsyncResultHandler.ReadyStateChanged;
}
oXmlHttp.open("POST", sUrl, async);
oXmlHttp.setRequestHeader("SOAPAction", sNamespace + "/" + sCommand);
oXmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
oXmlHttp.setRequestHeader("Content-Length", sXmlDocument.length);
oXmlHttp.send(sXmlDocument);
if (!async)
{
return new RemoteCommandResult(this, oXmlHttp);
}
}
}
function AsyncResultHandler(oRemoteCommand, oXmlHttp, funCallback)
{
this.ReadyStateChanged = readyStateChanged;
function readyStateChanged()
{
if (oXmlHttp.readyState == 4)
{
if (oXmlHttp.status != 0)
{
var result = new RemoteCommandResult(oRemoteCommand, oXmlHttp);
funCallback(result);
oXmlHttp.abort();
}
}
}
}
function CommandParameter(sName, sValue)
{
this.Name = sName;
this.Value = HtmlEncode(sValue.toString());
this.GetXml = getParameterXml;
function getParameterXml()
{
var sXml = "<" + this.Name + ">";
if (RemoteIsArray(this.Value))
{
var sType = this.Value.type;
if (RemoteIsNull(sType) && this.Value.length > 0)
{
sType = "object";
}
for (var i = 0; i < this.Value.length; i++)
{
sXml += "<" + sType + ">" + this.Value[i] + "</" + sType + ">";
}
}
else
{
sXml += this.Value;
}
sXml += "</" + this.Name + ">";
return sXml;
}
function HtmlEncode(text)
{
text = text.replace(/&/g, "&");
text = text.replace(/"/g, """);
text = text.replace(/</g, "<");
text = text.replace(/>/g, ">");
text = text.replace(/'/g, "’");
return text ;
}
}
function RemoteCommandResult(oRemoteCommand, oXmlHttp)
{
var sCommand = oRemoteCommand.Command;
var oText = oXmlHttp.responseText;
var Re = new RegExp('\<'+ sCommand +'Result\>([\\s\\S]+?)\<\/'+ sCommand +'Result\>','m');
var val = null;
if(Re.test(oText))
{
val = RegExp.$1;
}
this.ReturnValue = fromString(val);
function fromString(sValue)
{
if(sValue == null){
return null;
}
if (sValue.toLowerCase() == "true")
{
return true;
}
else if (sValue.toLowerCase() == "false")
{
return false;
}
var intValue = parseInt(sValue, 10);
if (!isNaN(intValue) && intValue.toString() == sValue)
{
return intValue;
}
var floatValue = parseFloat(sValue);
if (!isNaN(floatValue) && floatValue.toString() == sValue)
{
return floatValue;
}
// var dateValue = new Date(sValue);
// if (!isNaN(dateValue))
// {
// return dateValue;
// }
return HtmlDecode(sValue);
}
function HtmlDecode(s)
{
if (typeof(s) != "string")
{
return s;
}
s = s.replace(/\\n/g, '\n');
s = s.replace(/&/g, '&');
s = s.replace(/</g, '<');
s = s.replace(/>/g, '>');
return s.replace(/"/g, '"');
}
}
function RemoteIsNull(o)
{
return ("undefined" == typeof(o) || "unknown" == typeof(o) || null == o);
}
function RemoteIsArray(item)
{
return item != null && ((item instanceof Array) || (typeof item.splice) == "function");
}
function AttendOnOffDuty(code, obj) {
if (obj == 'onduty') {
if (!confirm('确定打上班卡吗?')) {return; }
} else {
if (!confirm('确定打下班卡吗?')) { return; }
}
HttpUrlCommand('/MyAdmin/HRM/Attend/Actions.aspx?t=onoffduty&act='+obj+'&code=' + code);
var o = document.getElementById(obj);
CreatLoadingLayer(document.getElementById('onoffduty'));
HttpUrlCommand(window.location.pathname + window.location.search, page_callback);
function page_callback(res) {
// var re1 = new RegExp('<span\\sid="onduty">([\\s\\S]+?)</span>', 'img');
// if (re1.test(res) == true) {
// document.getElementById('onduty').innerHTML = RegExp.$1;
// }
// var re2 = new RegExp('<span\\sid="offduty">([\\s\\S]+?)</span>', 'img');
// if (re2.test(res) == true) {
// document.getElementById('offduty').innerHTML = RegExp.$1;
// }
var re = new RegExp('<dl\\sid="onoffduty"\\sstyle="padding:0; margin:0">([\\s\\S]+?)</dl>', 'img');
if (re.test(res) == true) {
document.getElementById('onoffduty').innerHTML = RegExp.$1;
}
}
}
调用 <script type="text/javascript">
function show() {
// alert($("#ss").val());
var cmd = new RemoteCommand('WebService1', 'HelloWorld');
this.CommandParameter
alert(cmd.Execute().ReturnValue);
}
</script>