工作中用到的非常有用的JS调用WebService

// 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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值