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.
- $.ajax({
- type: "POST",
- url: "myMethods.aspx/myHtml",
- data: "",
- contentType: "application/json; charset=utf-8",
- dataType: "json",
- success: function (msg) {
- processResponse(msg);
- }
- });
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:
- {"d":"
| Column 1 |
Name |
|
| Some Data |
Some Data |
|
"}
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?
- $('#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