工作中用到的非常有用的JS调用WebService
2008-02-13 17:14
316 查看
// JScript 文件
function submitvote(vnum){
var xmlHttp=createXH();
xmlHttp.open("POST","http://test1.com:5750/VoteWebService.asmx/vote",false);
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttp.send("vnum="+vnum);
var message=xmlHttp.responseXML;
var result=message.childNodes[1].text;
if(result.indexOf('|')>0){
var arr = result.split('|');
var obj = document.getElementById("mm"+vnum);
obj.innerText=arr[1];
if(arr[0]=='1'){
alert('投票成功!');
}else{
alert('每人每天只能投一票!');
}
}
}
function initvotedata(vnum){
var xmlHttp=createXH();
var message;
var result;
var obj;
xmlHttp.open("POST","http://test1.com:5750/VoteWebService.asmx/showvotenum",false);
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttp.send("vnum="+vnum);
message=xmlHttp.responseXML;
result=message.childNodes[1].text;
obj = document.getElementById("mm"+vnum);
obj.innerText=result;
}
function createXH(){
var A=null;
try {
A=new ActiveXObject('Msxml2.XMLHTTP'); //1.0
}
catch(e) {
try{
A=new ActiveXObject('Microsoft.XMLHTTP');//1.1
}
catch(oc) {
A=null;
}
}
if ( !A && typeof XMLHttpRequest != 'undefined' )
{
A=new XMLHttpRequest();
}
return A;
}
此外必须在VS2005版的WEB.CONFIG中添加
<system.web>
<webServices>
<protocols>
<add name="HttpSoap" />
<add name="HttpPost" />
<add name="HttpGet" />
<add name="Documentation" />
</protocols>
</webServices>
</system.web>
function submitvote(vnum){
var xmlHttp=createXH();
xmlHttp.open("POST","http://test1.com:5750/VoteWebService.asmx/vote",false);
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttp.send("vnum="+vnum);
var message=xmlHttp.responseXML;
var result=message.childNodes[1].text;
if(result.indexOf('|')>0){
var arr = result.split('|');
var obj = document.getElementById("mm"+vnum);
obj.innerText=arr[1];
if(arr[0]=='1'){
alert('投票成功!');
}else{
alert('每人每天只能投一票!');
}
}
}
function initvotedata(vnum){
var xmlHttp=createXH();
var message;
var result;
var obj;
xmlHttp.open("POST","http://test1.com:5750/VoteWebService.asmx/showvotenum",false);
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttp.send("vnum="+vnum);
message=xmlHttp.responseXML;
result=message.childNodes[1].text;
obj = document.getElementById("mm"+vnum);
obj.innerText=result;
}
function createXH(){
var A=null;
try {
A=new ActiveXObject('Msxml2.XMLHTTP'); //1.0
}
catch(e) {
try{
A=new ActiveXObject('Microsoft.XMLHTTP');//1.1
}
catch(oc) {
A=null;
}
}
if ( !A && typeof XMLHttpRequest != 'undefined' )
{
A=new XMLHttpRequest();
}
return A;
}
此外必须在VS2005版的WEB.CONFIG中添加
<system.web>
<webServices>
<protocols>
<add name="HttpSoap" />
<add name="HttpPost" />
<add name="HttpGet" />
<add name="Documentation" />
</protocols>
</webServices>
</system.web>
相关文章推荐
- JS调用SharePoint 2007 WebService
- JQuery调用WebService,以及JS把单斜杠转换成双斜杠
- JS调用WEBSERVICE!
- Salesforce 使用Js 调用Webservice实例
- Oracle数据库是一个大家都非常熟悉的数据库管理系统,是工作中会经常要用到的,关于Oracle数据库中的dba和sysdba相信很多人都会经常把他们两个给搞混了,下文中将为大家讲解Oracle中db
- 关于js实现的Ajax调用,webService,一般处理程序,aspx
- NET-使用Js调用WebService
- 动态调用WebService(C#) (非常实用)
- [导入]一个简单的用JS调用WebService的例子
- 关于js实现的Ajax调用,webService,一般处理程序,aspx
- JS调用WebService示例
- php根据ip查询所在地区(非常有用,赶集网就用到)
- 非常不错的漂浮广告代码(须调用外部JS文件)
- JS-JQuery(JSONP)调用WebService跨域若干技术点
- JS调用WebService示例
- js调用webservice中的方法实现思路及代码
- js调用WebService的几种方法
- 动态调用WebService(C#) (非常实用)转载
- webservice跨域文件,好多年前的东西,远程调用,js服务器端使用,可以远程调用
- 非常有用的JS事件功能