这是我的ajax调用:
response = $.ajax({
type: "POST",
url: "/Row/getRowName",
dataType: "json",
data:({ currRow : rowName, offset : 5 }),
error:function(request){alert(request.statusText)},
success:function(result){alert(result)}
}).responseText;
我收到内部服务器错误作为警报。我还在我的 RowController 的方法 getRowName 中设置了一个断点。
这是 getRowName 方法:
[AcceptVerbs(HttpVerbs.Post)]
public string getRowName(string currRow, int offset)
{
string rowName;
rowName = _rowRepository.getRowNameByOffset(currRow, offset);
return rowName;
}
是什么导致内部服务器错误?我该如何解决?我是否正确使用了整个控制器概念,还是应该将 WebServices 用于此类事情?
编辑:调用页面的控制器是 HomeController,而我正在调用的是 RowController。RowController 与 HomeController 位于同一文件夹中(不确定是否重要)。
但是我发现如果我创建了一个模拟函数:
[AcceptVerbs(HttpVerbs.Post)]
public string sayHi()
{
return "Hi";
}
并以相同的方式调用它(不同的 url,因为它在家庭控制器中):
response = $.ajax({
type: "POST",
url: "/Home/sayHi",
dataType: "json",
error:function(request){alert(request.statusText)},
success:function(result){alert(result)}
}).responseText;
关于为什么这会起作用而另一个不会起作用的任何想法?