2016-07-26 2 views
0

Я пытаюсь использовать веб-сервис. Я новичок в веб-сервисах. Проблема здесь заключается в том, что я не получаю никакого ответа и код просто выдает ошибку и не будет вводить код успеха на всех:Использование мыла webservice с использованием 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: невозможно указать свойство" documentElement "неопределенного или нулевого refernece" – ploofah

+0

попытаться добавить метатег Anil

ответ

0

проблема была с веб-службой, он был решен путем размещения некоторые заголовки в файле 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

thankyou, теперь он предупреждает об успешном завершении, но теперь ответ равен null. – ploofah

+0

Вам нужно проверить веб-метод HelloWorld of the r service «http://172.16.15.112:786/Members.asmx», это должно возвращать null. – Anil