Reputation: 305
How can I pass parameter to .NET web method with fancytree
Public Shared Function ReadNodes(parentId As String) As String
I am trying to send it like this, but it always gets sent as a querystring parameter.
$("#tree").fancytree( {
source: {
url: "Default.aspx/ReadNodes",
data: {parentId: "-1"},
cache: false
}
} )
Can I somehow pass the value to a method as a parameter?
This doesnt work, I keep getting a loading wheel and then a failure. No javascript errors in console.
I have also tried the server method without a parameter, and I get the same behavior. So perhaps I am doing something else wrong.
Upvotes: 1
Views: 730
Reputation: 566
Your web method must return an array like:
[WebMethod]
public static IEnumerable ReadNodes(int parentId)
{
return new[] {
new { title = string.Format("1. Child of '{0}'", parentId) },
new { title = string.Format("2. Child of '{0}'", parentId) }
// ...
};
}
And then you call the web method like this
$('#tree').fancytree({
source: {
type: 'POST',
url: 'Default.aspx/ReadNodes',
data: '{ parentId: -1 }',
contentType: 'application/json;',
dataType: 'json'
}
});
Upvotes: 1