Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Seeing as this question has almost 600 views and no answers I thought I would answer it myself (since I've long since figured it out).</p> <p>Using a <code>ScriptMethod</code> is really not the right way to communicate with jQuery ajax. While it can be done, you will notice what I was doing above is returning a <code>string</code> with data that I encoded myself to JSON using <code>JavascriptSerializer.</code></p> <p>However, using a <code>ScriptMethod</code> automatically incorporates serialization/deserialization designed to communicate with Microsoft's AJAX framework. Since serializing a pure string with no object wrapper will genererally result in the same string (whether I be returning XML or JSON format), it basically worked, but what was really happening internally is it was being serialized <em>twice</em>.</p> <p>So what I should have done, at a minimum, was:</p> <p><code>public List&lt;jsTreeNode&gt; GetChildren(string id)</code></p> <p>that is, the return type should be the actual data type, not a string of serialized data. </p> <p>However, this still wouldn't be exactly right, because Microsoft's methods wrap the return value in an object <code>d</code>. I could still extract that in Javascript to get the inner data. But if something like jsTree is expecting data in a predefined format this may not be workable.</p> <p>The best solution is <strong>do not use WebServices, use generic handlers (ashx) instead.</strong> This gives you complete control over the format and handling of your input and output. It may take a little bit of doing to set yourself up a nice framework, but the frustration of being unable to skip parts of the WebService handling that you don't need makes it well worth it. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload