小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

JS調(diào)用web service的通用函數(shù)

 青格兒 2010-04-13

http://www./showtopic-22580.html

調(diào)用:

RequestByPost(method,variable,value,url,_Namespace)

 

method:web service的方法名

variableweb service的方法的變量名數(shù)組

valueweb service的方法的變量的值的數(shù)組

url:請(qǐng)求的地址(asmx文件地址)

_Namespaceweb service的命名空間

 

<script language="javascript" type="text/javascript">

// <!CDATA[

//define

var xmlhttp;

var value=new Array();

var variable=new Array();

//Show Response MSG.

function handleStateChange()

{

    var h=document.getElementById("Label1");

    if(xmlhttp.readyState==4)

    {

        if(xmlhttp.status==200)

        {

            alert(xmlhttp.responseText);

            h.innerHTML=xmlhttp.responseText;

            //h.innerHTML=xmlhttp.responseXML;

        }

        else if(xmlhttp.status==404)

        {

            h.innerHTML="<br>找不到請(qǐng)求的服務(wù)器資源!";

        }

    }

    else if(xmlhttp.readyState==0)

    {

        h.innerHTML="<br>未初始化!";

    }

    else if(xmlhttp.readyState==1)

    {

        h.innerHTML="<br>正在加載……!";

    }

    else if(xmlhttp.readyState==2)

    {

        h.innerHTML="<br>已經(jīng)加載完成!";

    }

    else if(xmlhttp.readyState==3)

    {

        h.innerHTML="<br>正在和服務(wù)器交互";

    }

    else

    {

        h.innerHTML=xmlhttp.responseXML;

}

}

//Get Request Data's length

 

function getlen(str)

{

var bytesCount=0;

for (var i = 0; i < str.length; i++)

{

var c = str.charAt(i);

if (/^[\u0000-\u00ff]$/.test(c))  //匹配雙字節(jié)

      {

bytesCount += 1;

}

else

{

bytesCount += 2;

}

}

return bytesCount;

} 

//Create XMLHttpRequest Object

  function createXMLHttpRequest()

{

    if(window.ActiveXObject)

    {

        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

    }

    else if(window.XMLHttpRequst)

    {

        xmlhttp=new XMLHttpRequest();

    }

} 

//send Request By HTTP POST

function RequestByPost(method,variable,value,url,_Namespace)

{

createXMLHttpRequest();

var data;

data = '<?xml version="1.0" encoding="utf-8"?>';

data = data + '<soap:Envelope xmlns:xsi="http://www./2001/XMLSchema-instance" xmlns:xsd="http://www./2001/XMLSchema" xmlns:soap="'">http://schemas./soap/envelope/">';

data = data + '<soap:Body>';

data = data + '<'+method+' xmlns="'+_Namespace+'">';

for(var i=0;i<variable.length;i++)

{    data = data + '<'+variable[i]+'>'+value[i]+'</'+variable[i]+'>';

}

data = data + '</'+method+'>';

data = data + '</soap:Body>';

data = data + '</soap:Envelope>';

xmlhttp.onreadystatechange=handleStateChange;

xmlhttp.Open("POST",url, true);

xmlhttp.SetRequestHeader ("Content-Type","text/xml; charset=utf-8");

xmlhttp.SetRequestHeader ("Content-Length",getlen(data));

xmlhttp.SetRequestHeader ("SOAPAction",_Namespace+method);

xmlhttp.Send(data);

alert(data);

}

//CallHelloWorld!

function SayHello_onclick() {

//alert(document.getElementById('YourName').value);

  RequestByPost("HelloWorld",new Array("msg"),new Array(document.getElementById('YourName').value),"WebService.asmx","localhost/");

}

//WeatherReport Test:

function Button2_onclick() {

RequestByPost("getWeatherbyCityName",new Array("theCityName"),new Array(document.getElementById('CityName').value),"http://www./WebServices/WeatherWebService.asmx","http://WebXml.com.cn/");

}

// ]]>

</script>

默認(rèn)的命名空間名字應(yīng)該以“/”結(jié)尾

 
另:相關(guān)連接請(qǐng)參考:
常用WebServices返回?cái)?shù)據(jù)的4種方法比較
http://www./showtopic-23733.html
MooTools國(guó)外經(jīng)典實(shí)例與教程大集合
http://www.cnblogs.com/delphi2007/articles/1602502.html
http:///tutorials/mootools/1045.html
http://www.cnblogs.com/luluping/archive/2008/05/04/1181665.html
在.net中集成Mootools做圖片動(dòng)態(tài)翻頁(yè)
http://kb.cnblogs.com/a/1414420/

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多