2016-07-26 107 views
0

我想消费一个web服务。我是webservices的新手。这里的问题是,我没有得到响应和代码只是生成错误并不会在所有进入的成功代码:消费肥皂web服务使用ajax jquery

<!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: unable to get property 'documentElement' of undefined or null refernence"

+0

你正在得到哪个错误?添加例外详情将有所帮助。 – Anil

+0

“TypeError:无法将gt属性'documentElement'的未定义或空引用” – ploofah

+0

尝试添加元标记 Anil

回答

0

的问题是与Web服务,它通过将一些标题中出现global.config文件来解决。

+0

您是否可以编辑您的答案以包含您的修补程序,以便其他人可以从您的解决方案中受益? – Todd

0

发布XML在IE中你应该添加元标记。

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

下面是工作代码,数据类型应该是文本和内容类型应该是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); 
    } 
}); 

对于浏览器所需的内容,请参阅所以question

+0

这不工作:| – ploofah

+0

谢谢,它现在确实提醒成功,但现在响应无效。 – ploofah

+0

你需要检查你的web方法HelloWorld服务“http://172.16.15.112:786/Members.asmx”,这应该返回null。 – Anil