Returning Json In Asp.net Webservice
In my application,we use the prototype1.4.2 in the page. And we need the tree view which support lazy load(make a ajax request and add the data from the server to the node),then I
Solution 1:
you can use jquery to do an Ajax call.
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "webServiceUrl/MethodName",
data: "{Id: '" + id + "'}",
dataType: "json",
success: loadSucceeded,
error: loadFailed,
async: true
});
functionloadSucceeded(result, status)
{
var data = result.d;
}
functionloadFailed(result, status)
{
}
Note that it is not necessarily to return a string, you can return a list of object.
[WebService(Namespace = "http://microsoft.com/webservices/";
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
publicclassUtilService: WebService
{
[WebMethod]
publicList<string> loadData(id) {
//some logic according the idreturnnew List<string>(){"data"};
}
}
Post a Comment for "Returning Json In Asp.net Webservice"