js 呼叫 WebService 方法

ForTechnology發表於2013-03-22
 

        function PostRequestData(URL, data) {

            var xmlhttp;
            if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp = new XMLHttpRequest();
            }
            else {// code for IE6, IE5
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }

            xmlhttp.Open("POST", URL, false);

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

            xmlhttp.SetRequestHeader("SOAPAction", "http://tempuri.org/myService/test/isNumner");



            try {

                xmlhttp.Send(data);

                var result = xmlhttp.status;

            }

            catch (ex) {

                return ("0" + ex.description + "|" + ex.number);

            }

            if (result == 200) {

                return ("1" + xmlhttp.responseText);

            }

            xmlhttp = null;

        }



        function loadit(value) {

            var url = 'http://localhost/myService/test.asmx';

            var data;

            var r;

            data = '';

            data = data + '';

            data = data + '';

            data = data + '';

            data = data + '' + value + '';

            data = data + '
';

            data = data + '';

            data = data + '
';

            r = PostRequestData(url, data);

            document.write(r);

        }

        loadit('5');

   

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25897606/viewspace-756798/,如需轉載,請註明出處,否則將追究法律責任。

相關文章