Should I pass back a data object or html when using ajax?

Should I pass back a data object or html when using ajax?

Hello,

I'm successfully using the following code to return some html via JSON.




  1.     $.ajax({
  2.         type: "POST",
  3.         url: "myMethods.aspx/myHtml",
  4.         data: "",
  5.         contentType: "application/json; charset=utf-8",
  6.         dataType: "json",
  7.         success: function (msg) {
  8.             processResponse(msg);
  9.         }
  10.     });

Now I wanted to store this html in a cookie for later use but as I'm using the .net framework I get issues with .net blocking anything that looks like script in a cookie.

I looked at the json response from this ajax call with firebug and it looked like:





  1. {"d":"
    Column 1 Name
    Some Data Some Data
          
            1
          "}
but when I do

EDIT: Looking at how the above has been rendered I see it looks like the browser is decoding the html within the JSON?




  1. $('#results').html(msg.d);

it renders the correct html

So my question is, should I be trying to either

1) store the JSON in it's original format in the cookie to bypass .net's security block and then decode it manually when I want to inject it into the page

or

2) Don't return html at all from the server and store a JSON data object in the cookie and then write out the html with this object via jquery.

The reason I am attempting 1 in the first place is that I currently use server-side templates to render HTML but I'm open to 2 if recommended.

Many Thanks

Dan