This is first time that I work with json. I am trying to return Json from my action method:
public JsonResult Upload()
{
...
return Json(new { foo = "sos....sos....sos..."});
}
But in result all I get is my message wrap in this "pre" tag. How to parse "foo" from this?
"<pre style="word-wrap: break-word; white-space: pre-wrap;">{"foo":"sos....sos....sos..."}</pre>"
This is first time that I work with json. I am trying to return Json from my action method:
public JsonResult Upload()
{
...
return Json(new { foo = "sos....sos....sos..."});
}
But in result all I get is my message wrap in this "pre" tag. How to parse "foo" from this?
"<pre style="word-wrap: break-word; white-space: pre-wrap;">{"foo":"sos....sos....sos..."}</pre>"
Share
Improve this question
asked Sep 26, 2011 at 18:22
11101110
6,82956 gold badges186 silver badges346 bronze badges
3 Answers
Reset to default 13I think the reason you are receiving the data wrapped in a pre tag is because you are requesting the data as HTML and not plain text or json.
Try specifying the data type as json to stop the response being converted to HTML.
This returns the content of the first pre tag with the class "yourclass".
document.querySelector("pre.yourclass").innerHTML
It's possible that the handler on the client side is trying to ensure that the server's response is well formed HTML. I believe some javascript libraries with file upload support will wrap non-HTML repsonses in the tag as you describe. A very non-intuitive solution might be to set the mimetype at the server to be "text/html", so that the ajax handler doesn't try to wrap the response.