How To Call C# Method With No Parameters And Access Returned Data?
So I have seen many examples such as these : https://stackoverflow.com/a/8094230/2525507 public class WebService : System.Web.Services.WebService { [WebMethod] public List&l
Solution 1:
If your method takes no arguments, just don't specify the data property on the ajax call
<script>
$(function () {
$.ajax({
url: 'WebService.asmx/getList',
type: 'POST',
dataType: 'json', //make sure your service is actually returning json herecontentType: 'application/json',
success: function (data, status) {
//here data is whatever your WebService.asmx/getList returned//populate your dropdown here with your $.each w/e
}
});
});
</script>
Also I could be wrong, but the WebService method you showed, doesn't look like it will return json. I think you will have to serialize, or set the content type or something similar. (Been along time since I've used the asmx type services)
Solution 2:
See my answer to this post. I reference a web site called Encosia, written by Dave Ward. He has an excellent series on using Ajax with ASP.net / MVC. That is a great place to start, with numerous examples.
Post a Comment for "How To Call C# Method With No Parameters And Access Returned Data?"