来自javascript的webservice调用中的问题

时间:2016-04-08 08:01:26

标签: javascript asp.net web-services

我试图通过javascript调用我的asp.net网络服务,但我不知道为什么呼叫不会发生。我检查了chrome中的log cat,redaystate总是1意味着建立了连接。那为什么我不能得到回应呢?

这是我的index.html文件

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
        <title></title>
        <link href="lib/ionic/css/ionic.css" rel="stylesheet">
        <link href="css/style.css" rel="stylesheet">
        <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
        <link href="css/ionic.app.css" rel="stylesheet">
        -->
        <!-- ionic/angularjs js -->
        <script src="lib/ionic/js/ionic.bundle.js"></script>
        <!-- cordova script (this will be a 404 during development) -->
        <script src="cordova.js"></script>
        <!-- your app's js -->
        <script src="js/app.js"></script>
        <!--<script src="lib/ionic/js/angular.soap.js"></script>
        <script src="lib/ionic/js/soapclient.js"></script>-->
        <script type="text/javascript">
        function soap() {
            var xmlhttp = new XMLHttpRequest();
            xmlhttp.open('POST','http://http://192.168.1.7:8100//NovitymRechargeWS/service.asmx', true);
            var methodName = 'GetServiceList'
            var sRequest = '<MRREQ><REQTYPE>GSL</REQTYPE><MOBILENO>8460883677</MOBILENO><SMSPWD>1414</SMSPWD></MRREQ>'
            var sReqData = encodeURI(sRequest);
            // build SOAP request
            var sr =
                '<?xml version="1.0" encoding="utf-8"?>' +
                '<soap:Envelope' + 
                    'xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ' +
                    'xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" ' +
                    'xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\">' +
                    '<soap:Header>' + 
                    '<NRSoapHeader xmlns=\"http://tempuri.org/\">'+
                    '<UserID>9898908000</UserID>'+
                    'Password>123</Password>'+
                    '</NRSoapHeader>'+
                    '</soap:Header>'+
                    '<soap:Body>'+
                    '<'+ methodName + ' xmlns=\"http://tempuri.org/\">'+
                    '<sRequest>' + sReqData + '</sRequest>'+
                    '</'+ methodName + '>'+
                    '</soap:Body>' +
                '</soap:Envelope>';

            // Send the POST request
            xmlhttp.setRequestHeader('Content-Type', 'text/xml');
            xmlhttp.send(sr);

            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4) {
                    if (xmlhttp.status == 200) {
                        alert('done. use firebug/console to see network response');
                    }
                }
            }
            // send request
            // ...
        }
    </script>
    </head>
    <body ng-app="starter" ng-controller="AppCtrl">
        <ion-pane>
            <ion-header-bar class="bar-stable">
                <h1 class="title">Ionic Blank Starter</h1>
            </ion-header-bar>

            <ion-content padding="true">
                <form>
                    <label class="item item-input item-stacked-label">
                        <span class="input-label">Username</span>
                        <input type="text" name="username" placeholder="enter username" ng-model="data.username">

                        <span class="input-label">Password</span>
                        <input type="text" name="p`assword" placeholder="enter Password" ng-model="data.password">
                    </label>

                    <input class="button button-block button-positive" type="submit" name="submit" value="Submit to server" onclick="soap();">                    
                </form>
                </div>
            </ion-content>
        </ion-pane>
    </body>
</html>

0 个答案:

没有答案