I made this web service that returns a datatable from sql server db. Can someone help me with the jquery to display it?
web service
[WebService(Name
In the past, when using asmx services with jQuery, I used something like the following for post/json:
Assuming that I had a response class like this:
public ResponseClass
{
public string Message { get; set; }
}
And a webservice with a method like this:
[WebMethod]
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
public ResponseClass PostResponse()
{
var response = new ResponseClass() {Message = "Hello World"};
return response;
}
Some html like this:
The javascript:
$.ajax({
url: '/MyService.asmx/PostResponse',
data: "{}",
type: "POST",
cache: false,
dataType: 'json',
contentType: "application/json; charset=utf-8",
success: function(msg) {
var response = msg.d; //your response object
$('#response').html(response.Message); //set the response div contents to the Message
},
error: function(xhr, status, error) {
alert(error); //do something if there is an error
}
});