开发者

Retrieve values from getJSON() call in jQuery

I have an ajax call in my jquery to my MVC controller:开发者_JS百科

$.getJSON('/mysite/controller/dosomething', { postId: id }, function (data) {

The 'data' that I am returning is in the form of a JsonResult, and consists of a simple custom object with 1 property called 'Message' and another property called 'Count'. Both of these values are assigned and I am returning them as follows (edited for brevity):

[HttpGet]
public JsonResult DoSomething(int postId)
{
    var response = new MyAjaxResponseModel {Message = "Hello world!", Count = 66};
    return Json(response, JsonRequestBehavior.AllowGet);
}

In my jQuery, I then want to be able to look at both values in the Json response, but I don't know the proper way to get at these values?


data.Message, data.Count in the callback you're passing to $.getJSON()? To inspect the structure of your data object, you can use console.log(data) (also, in that callback)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜