Saturday, April 14, 2012

WebService: Request format is unrecognized for URL unexpectedly ending in {/MethodName}

All you need is to add the following to your web.config

<webServices>
     <protocols>
          <add name="HttpGet" />
          <add name="HttpPost" />
     </protocols>
</webServices>

and call the service this way

<script type="text/javascript">
$.ajax({
       type: "POST",
       url: "CatsService.asmx/GetCatsByID",
       data: "{id: " + li.attr("rel") + " }",
       contentType: "application/json; charset=utf-8",
       dataType: "json",
       success: function (o) {
           o = o.d;
           for (var i = 0; i < o.length; i++) {
           $('ul').append('<li><a href="javascript:void(0)">' + o[i].title + '</a></li>');
           }
       }
});
</script>

All is done

No comments:

Post a Comment