0

I'm trying to consume a webservice. I'm new to webservices. The problem here is that I'm getting no response and the code just generates an error and won't enter the success code at all:

<!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>

Any help will be appreciated.

The error is:

"TypeError: unable to get property 'documentElement' of undefined or null refernence"

ploofah
  • 77
  • 10

2 Answers2

0

to post XML in IE you should add meta tag.

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

below is working code, data type should be text and content type should be text/xml. try this, the error alerts will help to trace actual problem.

$.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);
    } 
}); 

For desired content of browser, refer so question

Community
  • 1
  • 1
Anil
  • 3,722
  • 2
  • 24
  • 49
  • thankyou, it does alert success now but the response is null now. – ploofah Jul 26 '16 at 10:18
  • You need to check web method HelloWorld of you r service "http://172.16.15.112:786/Members.asmx", this should be returning null. – Anil Jul 26 '16 at 10:20
  • the method has been defined to return the string hello world. – ploofah Jul 26 '16 at 11:49
  • "defiend to return" means, to accept only httpGet request. Here we are posting (httpPost) request. You may need to configure this function to accept POST request. so post http://stackoverflow.com/questions/618900/enable-asp-net-asmx-web-service-for-http-post-get-requests can help. – Anil Jul 26 '16 at 12:35
  • yes the problem was with the web service, it was resolved by placing some headers in the global.config file. – ploofah Jan 09 '17 at 19:34
0

the problem was with the web service, it was resolved by placing some headers in the global.config file.

ploofah
  • 77
  • 10
  • Can you edit you answer to include your fix so that others can benefit from your solution? – Todd May 11 '17 at 23:33