2015-04-02 57 views
0

我真的不知道为什么,但函数(响应) - 部分根本不会被执行 - 尽管我的控制器中的获取方法被getJSON调用。

脚本:

$.getJSON(getUrl, { 
     BUID: buID, 
     AID: aID, 
     LID: lID 
    }, function (response) { 
     $('#Test').text("TEST"); 
    }) 
}; 

控制器:

public JsonResult GetMeasures(int buID) { 
     return Json(new { Success = true }); 
    } 

我跨度元素的文本不会被改变成 “TEST”。

+0

'这是$ ('#Test')。text(“TEST”);' – lshettyl 2015-04-02 09:11:01

+0

@lshetty感谢您的回应 - 但即使使用$('#Test').text(“TEST”);它不工作。 – C4p741nZ 2015-04-02 09:13:38

+0

你真的需要解释_it不工作_因为我不知道什么是_it_! – lshettyl 2015-04-02 09:15:14

回答

0

发送正确的参数:

$.getJSON(getUrl, { 
     buID: buID 
    }, function (response) { 
     $('#Test').text("TEST"); 
    }) 
}; 

然后你需要使用JsonRequestBehavior.AllowGet与JSON回报,还与HttpGet属性装饰你的功能

[HttpGet] 
public JsonResult GetMeasures(int buID) { 
     return Json(new { Success = true }, JsonRequestBehavior.AllowGet); 
} 

一个良好的阅读Why is JsonRequestBehavior needed?