繁体   English   中英

使用Ajax jQuery消费Soap Web服务

[英]Consuming a soap webservice using ajax jquery

我正在尝试使用Web服务。 我是Web服务的新手。 这里的问题是我没有响应,并且代码只是生成一个错误,根本不会输入成功代码:

<!DOCTYPE html>
<html>
<head>
<title>
My Web Service Test Code using Jquery
</title>
<script src="js/jquery-1.4.1.min.js" type="text/javascript"></script>
</head>
<body>
<div>
<ul>
<form id="form1" runat="server">
<li>
    <label>Member ID</label>
    <input id="member_id" type="text" />
    <input id="blnLoadMember" type="button" value="Get Details"    onclick="javascript:GetMember();" />

</li>
</form>
</ul>    
<div id="MemberDetails"></div>

</div>
<script type="text/javascript">
var soapMessage = '<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><HelloWorld xmlns="http://tempuri.org/" /></soap:Body></soap:Envelope>';

function GetMember() {
    $('input[type=button]').attr('disabled', true);
    $("#MemberDetails").html('');
    $("#MemberDetails").addClass("loading");
    $.ajax({

        url: "http://172.16.15.112:786/Members.asmx/HelloWorld",
        type: "POST",
        dataType: "xml",
        data: soapMessage,
        processData: false,
        contentType: "text/xml; charset=\"utf-8\"",

        success: function (response) {
            alert("success");
            alert(response);
            console.log(response);

           // $('#MemberDetails').html(JSON.stringify(response.d));

        },

        error: OnGetMemberError
    });
}

function OnGetMemberError(request, status, error) {
    alert(error);
    $("#MemberDetails").removeClass("loading");
    $("#MemberDetails").html(request.statusText);
    $('input[type=button]').attr('disabled', false);
}

</script>
</body>
</html>

任何帮助将不胜感激。

错误是:

“ TypeError:无法获取未定义或空引用的属性'documentElement'”

要在IE中发布XML,您应该添加meta标签。

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

以下是工作代码,数据类型应为text,内容类型应为text / xml。 尝试此操作,错误警报将有助于跟踪实际问题。

$.ajax({
    url: "http://172.16.15.112:786/Members.asmx/HelloWorld",
    data: '<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><HelloWorld xmlns="http://tempuri.org/" /></soap:Body></soap:Envelope>', 
    type: 'POST',
    contentType: "text/xml",
    dataType: "text",
    success : function (response) {
        alert("success");
        alert(response);},
    error : function (xhr, ajaxOptions, thrownError){  
        alert(xhr.status);          
        alert(thrownError);
    } 
}); 

对于浏览器的所需内容,请参考问题

该问题与Web服务有关,已通过在global.config文件中放置一些标头解决了该问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM