views:

47

answers:

1

When I return a JSon value, i simply want to put a string inside an existing div

EDIT: Let me Rephrase this: I want my MVC controller to return a JSON object to the UpdateTarget specified in the MVC AJAX call. Instead of returning "content".

A: 

Assume your JSON String looks like this:

 var jobj = '{"name":"value"}';

and you have a div on the HTML with id mycontentdiv then

 document.getElementById("mycontentdiv").innerHTML = jobj.name;

will take the "value" and place it in the div.

Without further details it is difficult to be more specific.

Vincent Ramdhanie
er, lose the `()`. Also setting as a Text Node value may be what's wanted... the question's unclear, but putting values straight into `innerHTML` is dangerous, may be a XSS hole.
bobince
@bobince Thanks. I know the question is very unclear but I am guessing the intention. I corrected the ().
Vincent Ramdhanie