System.InvalidOperationException: This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet.
由错误信息可知MVC2出于对网站数据的保护,默认禁止通过get的请求返回JsonResult数据,你可以在返回Json时,传入第二个参数 JsonRequestBehavior.AllowGet,如:return Json(result, JsonRequestBehavior.AllowGet),当然你也可以修改你的前端代码,使用post的方式来获取数据。
$.ajax({
type: 'POST',
url: '<%= Url.Action("Json") %>',
contentType: 'application/json;charset=utf-8',
dataType: 'json',
data: '{}',
success: function(data) {
$("#Address").empty();
var html = "";
$.each(data, function(entryIndex, entry) {
if(entry["ParentID"]==0)
{
html+=entry["Addresses"]+" ";
}
if(entry["ParentID"]==1)
{
html+="<br>";
html+=entry["Addresses"]+" ";
}
});
$("#Address").append(html);
alert(data[0].Addresses);
}, error: function(xhr) {
alert('出现错误,服务器返回错误信息: ' + xhr.statusText);
}
});