使用javascript从sumtotal身份验证web服务获取安全上下文令牌

使用javascript从sumtotal身份验证web服务获取安全上下文令牌,javascript,web-services,security,soap,token,Javascript,Web Services,Security,Soap,Token,我试图使用sumtotal的学习管理系统基于soap的Web服务,并使用下面的代码来使用它。但我不知道如何从javascript中捕获服务的响应,因为我在这方面做得不多。请帮助 <script language="JavaScript" type="text/javascript"> function getData() { var xmlht

我试图使用sumtotal的学习管理系统基于soap的Web服务,并使用下面的代码来使用它。但我不知道如何从javascript中捕获服务的响应,因为我在这方面做得不多。请帮助

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

                            function getData()
                            {


     var    xmlhttp = new XMLHttpRequest();
      xmlhttp.open('GET',     'https://Testsoapservice.com/Services/authentication.asmx?op=Login', true);


            // 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://schemas.xmlsoap.org/soap/envelope/">'+
                    '<soapenv:Body>' +
                       ' <Login xmlns="http://www.testsoapservice.com/Authentication/">'+
                       '<credentials>'+
'<Username>xxx</Username>'+
                            '<Passcode>xxxx</Passcode>'+                            
                        '</credentials>'+
                        '</Login>'+
                    '</soapenv:Body>' +
                '</soapenv:Envelope>';

            xmlhttp.onreadystatechange = function () {


                if (xmlhttp.readyState == 4) {      

                    if (xmlhttp.status == 200) {
        // How to get the user token here as  soap response. I would like to use the token to consume subsequent services
                    }
                }
            }
            // Send the POST request
            xmlhttp.setRequestHeader('Content-Type', 'text/xml');
            xmlhttp.send(sr);


                        }
    </script>

函数getData()
{
var xmlhttp=new XMLHttpRequest();
open('GET','https://Testsoapservice.com/Services/authentication.asmx?op=Login",对),;
//生成SOAP请求
var sr=''+
''+
'' +
' '+
''+
“xxx”+
“xxxx”+
''+
''+
'' +
'';
xmlhttp.onreadystatechange=函数(){
如果(xmlhttp.readyState==4){
if(xmlhttp.status==200){
//如何在这里获取用户令牌作为soap响应。我想使用该令牌来使用后续服务
}
}
}
//发送POST请求
setRequestHeader('Content-Type','text/xml');
xmlhttp.send(sr);
}

答案是:很简单,但我尝试了不同的东西。这很有效

 <script type="text/javascript">
            $(document).ready(function () {
            $("#btnCallWebService").click(function (event) {
            var wsUrl = 
"https://Testsoapservice.com/Services/authentication.asmx";

        xmlhttp.open('GET',     
'https://Testsoapservice.com/Services/authentication.asmx?op=Login', true);


        // 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://schemas.xmlsoap.org/soap/envelope/">'+
                '<soapenv:Body>' +
                   ' <Login 
   xmlns="http://www.testsoapservice.com/Authentication/">'+
                   '<credentials>'+
'<Username>xxx</Username>'+
                        '<Passcode>xxxx</Passcode>'+                            
                    '</credentials>'+
                    '</Login>'+
                '</soapenv:Body>' +
            '</soapenv:Envelope>';
            $.ajax({
                type: "POST",
                url: wsUrl,
                contentType: "text/xml",
                dataType: "xml",
                data: soapRequest,
                success: processSuccess,
                error: processError
            });

        });
    });

    function processSuccess(data, status, req) 
    {

        if (status == "success")
          //  $("#response").text($(req.responseXML).find("Value").text());
            var uToken=$(req.responseXML).find("Value").text();

$(文档).ready(函数(){
$(“#btnCallWebService”)。单击(函数(事件){
var wsUrl=
"https://Testsoapservice.com/Services/authentication.asmx";
xmlhttp.open('GET',
'https://Testsoapservice.com/Services/authentication.asmx?op=Login",对),;
//生成SOAP请求
var sr=''+
'