我有一个JsonResult方法,我试图用jQuery Ajax调用但是我收到500服务器错误,其中包含运行时错误消息:
The method or operation is not implemented.
这是我的jQuery:
function submitPanel(value) {
var panelIds = [];
$('#' + value + ' select ').each(function () {
panelIds.push($(this).val());
});
$.ajax({
url: 'SavePanel',
data: {
chairId: panelIds[0],
coPanelistId: panelIds[1]
},
type: 'json',
success: function (data) {
$('#InterviewManagementFrm').html(data);
}
});
}
panelIds [0]和panelIds [1]有guid,因为我一直在使用警报来检查。
public JsonResult SavePanel(Guid chairId, Guid coPanelistId)
{
DataLayer.InterviewManagement.InterviewManagementDataLayer DataLayer = new InterviewManagementDataLayer();
//DataLayer.SavePanel(new Guid(chairId), new Guid(coPanelistId));
// TODO: success/failure logic returned from data layer method
var json_string = "{ success: \"true\" }";
return Json(json_string, JsonRequestBehavior.AllowGet);
}
这个JsonResult方法在我的控制器中,它没有做很多但是当它工作时它会与我的数据层交谈。
我是否忘记写一行代码或者我还缺少其他什么东西?
响应标题
Remote Address:::1:58719
Request URL:http://localhost:58719/InterviewManagement/SavePanel
Request Method:JSON
Status Code:500 Internal Server Error
Request Headersview source
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-GB,en-US;q=0.8,en;q=0.6
Connection:keep-alive
Content-Length:94
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Host:localhost:58719
Origin:http://localhost:58719
Referer:http://localhost:58719/InterviewManagement/InterviewManagementPage
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.137 Safari/537.36
X-Requested-With:XMLHttpRequest
Form Dataview sourceview URL encoded
chairId:6fe262de-a5b3-4c20-8b76-fab25ccd88ec
coPanelistId:72e42a86-cc98-45f0-9950-2b009ad0ec5d
Response Headersview source
Cache-Control:private
Connection:Close
Content-Length:10399
Content-Type:text/html; charset=utf-8
Date:Wed, 21 May 2014 14:11:34 GMT
Server:ASP.NET Development Server/10.0.0.0
X-AspNet-Version:4.0.30319
答案 0 :(得分:1)
你正在以错误的方式写你的ajax。您还没有定义.ajax类型,无论是Post还是Get。尝试写下你的ajax:
$.ajax({
url: '/InterviewManagement/SavePanel',
dataType: "json",
type: "POST",
data: {
chairId: panelIds[0],
coPanelistId: panelIds[1]
},
success: function (data) {
$('#InterviewManagementFrm').html(data);
}
});
希望这会对你有所帮助。
答案 1 :(得分:0)
我必须提供完整的URL路径才能正常工作。因为我的JS是在外部脚本中,所以我没有剃刀可用于获取虚拟路径。我最终做出了这个改变。
$.ajax({
url: '/InterviewManagement/SavePanel',
data: {
chairId: panelIds[0],
coPanelistId: panelIds[1]
},
type: 'json',
success: function (data) {
$('#InterviewManagementFrm').html(data);
}
});
感谢大家的帮助。