String response not getting in .getJSON
My controller method just return String value. When I called JSON from my view page, I don't see any value.
controller method
public string test(int i)
{
return "Hello world " + i;
}
Inside View,
$.getJSON(['../Feeds/test/', 1, '/'].join(''),
function(json) {
开发者_如何学运维 alert(json.toString());
});
If I run this into Mozilla, I can see "Hello world 1" in response but don't get any alert. What is wrong here?
because it is not a json object? I am not sure because never try return plain text output with getJSON
. why don't try get
function?
$.get(['../Feeds/test/', 1, '/'].join(''),
function(json) {
alert(json.toString());
}
);
Either make your controller return a JsonResult
return new JsonResult{Data = "Hello world " + i, JsonRequestBehavior = JsonRequestBehavior.AllowGet};
or use jquery's $.get()
which doesn't expect a json object.
精彩评论