使用jQuery从SOAP响应中解析XML [英] Parsing XML from SOAP response with jQuery

查看:94
本文介绍了使用jQuery从SOAP响应中解析XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用jQuery解析SOAP服务器的响应时遇到问题.

这是请求

POST /REMEDIFINDERSERVICES/HSWebService.asmx HTTP/1.1
Host: 192.168.1.24
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.healthsprint.com/NewUserRegistration"

<?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/">
<soap:Body>
<NewUserRegistration xmlns="http://www.healthsprint.com">
  <loginId>string</loginId>
  <Password>string</Password>
</NewUserRegistration>
</soap:Body>
</soap:Envelope>

这是回应

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?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/">
<soap:Body>
<NewUserRegistrationResponse xmlns="http://www.healthsprint.com">
  <NewUserRegistrationResult>int</NewUserRegistrationResult>
</NewUserRegistrationResponse>
</soap:Body>
</soap:Envelope>

这是我的代码

$("#signup_btn").click(function (event) {

var fornewUrl = "http://192.168.1.24/REMEDIFINDERSERVICES/HSWebService.asmx?op=NewUserRegistration";


var newforsoapRequest =
'<?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/"> \
<soap:Body> \
<NewUserRegistration xmlns="http://www.healthsprint.com"> \
  <loginId>' + $(".user").val() + '</loginId> \
  <Password>' + $(".pwd").val() + '</Password> \
 </NewUserRegistration> \
 </soap:Body> \
 </soap:Envelope>';


 $.ajax({
                type: "POST",
                url: fornewUrl,
                contentType: "text/xml",
                dataType: "xml",
                data: newforsoapRequest,
                success: newprocessSuccess,
                error: newprocessError
            });

            function newprocessSuccess(data, status, req) {
        if (status == "success")
            $(".u_name").text($(req.responseXML).find("loginId").text());

    }

    function newprocessError(data, status, req) {
        alert(req.responseText + " " + status);
    }   

        });

我需要将数据发送到登录ID和密码,并且需要将登录ID显示到其他页面,但是不知何故它在这里不起作用.

即使我将如何检查数据是否已发送到Web服务

预先感谢

解决方案

我不确定我是否完全理解这个问题,但是SOAP是XML.我想您可以使用 XML解析器来标识相应的XML元素并进一步使用它. /p>

希望我能帮上忙!

I have problems parsing response from SOAP server with jQuery.

this is request

POST /REMEDIFINDERSERVICES/HSWebService.asmx HTTP/1.1
Host: 192.168.1.24
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.healthsprint.com/NewUserRegistration"

<?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/">
<soap:Body>
<NewUserRegistration xmlns="http://www.healthsprint.com">
  <loginId>string</loginId>
  <Password>string</Password>
</NewUserRegistration>
</soap:Body>
</soap:Envelope>

and this is the response

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?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/">
<soap:Body>
<NewUserRegistrationResponse xmlns="http://www.healthsprint.com">
  <NewUserRegistrationResult>int</NewUserRegistrationResult>
</NewUserRegistrationResponse>
</soap:Body>
</soap:Envelope>

and this is my code

$("#signup_btn").click(function (event) {

var fornewUrl = "http://192.168.1.24/REMEDIFINDERSERVICES/HSWebService.asmx?op=NewUserRegistration";


var newforsoapRequest =
'<?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/"> \
<soap:Body> \
<NewUserRegistration xmlns="http://www.healthsprint.com"> \
  <loginId>' + $(".user").val() + '</loginId> \
  <Password>' + $(".pwd").val() + '</Password> \
 </NewUserRegistration> \
 </soap:Body> \
 </soap:Envelope>';


 $.ajax({
                type: "POST",
                url: fornewUrl,
                contentType: "text/xml",
                dataType: "xml",
                data: newforsoapRequest,
                success: newprocessSuccess,
                error: newprocessError
            });

            function newprocessSuccess(data, status, req) {
        if (status == "success")
            $(".u_name").text($(req.responseXML).find("loginId").text());

    }

    function newprocessError(data, status, req) {
        alert(req.responseText + " " + status);
    }   

        });

i need to send the data to login id and password and need to display login id to other page but somehow its not working here.

Even how i will check that data has sent to web service or not

thanks in advance

解决方案

I am not sure I understand the question fully but SOAP is XML. I suppose you could use an XML Parser to identify the respective XML element and use it further.

Hope I helped!

这篇关于使用jQuery从SOAP响应中解析XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆