作业帮 > 综合 > 作业

function WebService(url,callback,method)

来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/11 20:05:37
function WebService(url,callback,method)
{
try
{
var divPlan=document.createElement("div");
divPlan.innerHTML="
读取数据中,请稍候……
";
divPlan.style.styleFloat = "right";
divPlan.style.position= "absolute";
divPlan.style.margin = "auto";
divPlan.style.top = "10px";
divPlan.style.left = "10px";
divPlan.style.border = "1px solid #DDD";
divPlan.style.width = "200px";
divPlan.style.height = "30px";
divPlan.style.background = "#FFFFE0";
divPlan.style.filter = "alpha(opacity=90)";
divPlan.style.opacity = "0.90";
divPlan.style.zIndex = "999";
divPlan.style.display = "block";
document.body.appendChild(divPlan);
var xmldoc;
var webhttp = new WebObject(callback);
var index ;
var params = new Array;
var pn = 0;
var len = WebService.arguments.length;
for (var i=3; i < len; i++)
params[pn++] = WebService.arguments[i];
var cmd="WebObject_XML('" + method + "'";
for (var i=0; i < params.length; i++)
cmd += ",'" + escape(params[i]) + "'";
cmd += ")" ;
var xml=eval(cmd) ;
if(window.ActiveXObject)
{
xmldoc = new ActiveXObject("Microsoft.XMLDOM");
xmldoc.async="false";
xmldoc.loadXML(xml);
}
else
{
xmldoc = document.implementation.createDocument("","",null);
var parser=new DOMParser();
xmldoc=parser.parseFromString(xml,"text/xml");
}
if (typeof(callback) == 'function')
{
index=WebObject_Add(webhttp) ;
webhttp.xmlhttp.open("POST",url ,true) ;
webhttp.xmlhttp.onreadystatechange = WebObject_Callback ;
webhttp.xmlhttp.send(xmldoc);
xmldoc=null ;
return(index) ;
}
else
{
webhttp.xmlhttp.open("POST",url ,false) ;
webhttp.xmlhttp.send(xmldoc);
var exml='' ;
var tag = '//RETURN_VALUE' ;
exml=webhttp.xmlhttp.responseText;
xmldoc=null ;
webhttp=null ;
return(exml) ;
}
}
catch(e)
{
// alert(e.message);
}
finally
{
document.body.removeChild(divPlan);
}
}
function WebService(url,callback,method)
javascript 脚本,
20分解释这么多,太累了.
var divPlan=document.createElement("div");
//定义一个dive
//下面这么多都是定义这个div的样式的
divPlan.innerHTML="
读取数据中,请稍候……";
divPlan.style.styleFloat = "right";
divPlan.style.position= "absolute";
divPlan.style.margin = "auto";
divPlan.style.top = "10px";
divPlan.style.left = "10px";
divPlan.style.border = "1px solid #DDD";
divPlan.style.width = "200px";
divPlan.style.height = "30px";
divPlan.style.background = "#FFFFE0";
divPlan.style.filter = "alpha(opacity=90)";
divPlan.style.opacity = "0.90";
divPlan.style.zIndex = "999";
divPlan.style.display = "block";
//定义完样式后,添加到页面
document.body.appendChild(divPlan);
//下面这个是模拟一个http 请求,调用web service
var xmldoc;
var webhttp = new WebObject(callback);
var index ;
var params = new Array;//定义一个数组
var pn = 0;
var len = WebService.arguments.length;//web service 的参数长度为3
for (var i=3; i < len; i++)
params[pn++] = WebService.arguments[i]; //给web service 参数赋值
//定义命令语句的字符串
var cmd="WebObject_XML('" + method + "'";
for (var i=0; i < params.length; i++)
cmd += ",'" + escape(params[i]) + "'";
cmd += ")" ;
var xml=eval(cmd) ;//这里执行这个命令
if(window.ActiveXObject)//判断浏览器类型 这个是微软的IE
{
//生成一个DOM 对象
xmldoc = new ActiveXObject("Microsoft.XMLDOM");
xmldoc.async="false";
xmldoc.loadXML(xml);
}
else
{
//除了微软的IE ,都调用这个方法生成一个DOM 对象
xmldoc = document.implementation.createDocument("","",null);
var parser=new DOMParser();
xmldoc=parser.parseFromString(xml,"text/xml");
}
if (typeof(callback) == 'function')
{
//定义http请求的参数 post 调用 url
index=WebObject_Add(webhttp) ;
webhttp.xmlhttp.open("POST",url ,true) ;
webhttp.xmlhttp.onreadystatechange = WebObject_Callback ;
webhttp.xmlhttp.send(xmldoc);
xmldoc=null ;
return(index) ;//返回值是个int 类型的序号,具体做什么要看web service 怎么写的了
}
else
{
webhttp.xmlhttp.open("POST",url ,false) ;
webhttp.xmlhttp.send(xmldoc);
var exml='' ;
var tag = '//RETURN_VALUE' ;
exml=webhttp.xmlhttp.responseText;
xmldoc=null ;
webhttp=null ;
return(exml) ;
}
}
//这里都是异常处理了,
catch(e)
{
// alert(e.message);
}
finally
{
document.body.removeChild(divPlan);
}