views:

36

answers:

1

Two parts to my question:

  1. I need to format my web service responses for display on my web page. Should I use JavaScript to format the responses or given that it’s a .NET web service format the response as HTML and then simply push it down to the client?

  2. If I'm using JavaScript to manipulate the response, what datatypes should I avoid returning from a .NET web service that might not "play nice" with JavaScript?

Thanks for your help.

+2  A: 
  1. It depends on the context. If you're returning a simple string to update a <span>, then I would use javascript to format it. If you're returning an RSS feed, then I would format it server side. If you're using an autocompleter for a text box, it might be better to output the html with an IHttpHandler instead.
  2. If you use JSON (ScriptService) web service methods, it shouldn't matter what the .NET type is. The return value will be serialized as a JSON object.

Here's an excellent tutorial on consuming JSON ASP.NET web services with jQuery.

jrummell