[英]failed to load resource: the server response with a status 500 (internal server error)
i had build a web form with autocomplete method, the program is working fine in IDE.我已经使用自动完成方法构建了一个 web 表单,该程序在 IDE 中运行良好。 But after i publish the application to IIS, the method is not working.
但是在我将应用程序发布到 IIS 后,该方法不起作用。 the console show this error `failed to load resouces: server response with a status 500(internal server error) Index2).
控制台显示此错误`无法加载资源:服务器响应状态为 500(内部服务器错误)Index2)。 Im suspected the jquery code didn't recognize the controller name.
我怀疑 jquery 代码无法识别 controller 名称。
CSHTML
CSHTML
<script type="text/javascript">
$(document).ready(function () {
$("#CardName").autocomplete({
source: function (request, response) {
$.ajax({
url: "Index2",
type: "POST",
dataType: "json",
data: { Prefix: request.term },
success: function (data) {
response($.map(data, function (item) {
return { label: item.CardName, value: item.CardId };
}))
}
})
},
messages: {
noResults: "", results: ""
}
});
})
</script>
Controller Controller
[HttpPost]
public JsonResult Index2(string Prefix)
{
List<CardHolderDetails> getCardList = new List<CardHolderDetails>();
getCardList = _service.getCardList();
List<CardHolderDetails> ObjList = new List<CardHolderDetails>();
foreach (var value in getCardList)
{
ObjList.Add(new CardHolderDetails { CardId = value.CardId, CardName = value.CardName });
}
//Searching records from list using LINQ query
var CardName= (from N in ObjList
where N.CardName.StartsWith(Prefix)
select new { N.CardName, N.CardId });
return Json(CardName, JsonRequestBehavior.AllowGet);
}
The following code it is working fine during the development, but once publish to IIS it seem the jquery url
cannot be read.以下代码在开发过程中运行良好,但一旦发布到 IIS 似乎 jquery
url
无法读取。 any replacement for URL
to controller function name? URL
到 controller function 名称的任何替代品?
If your _service.getCardList()
returns null
then the foreach
will throw an exception which you have not handled. 如果
_service.getCardList()
返回null
则foreach
将抛出您尚未处理的异常。
Maybe that is the reason you are getting (500) internal server error
and not the jquery url
, as 500 error code suggests that something went wrong in the server code. 也许这就是你得到
(500) internal server error
而不是jquery url
,因为500错误代码表明服务器代码出了问题。
As a suggestion, You should use implement try - catch
and log the exceptions somewhere to be able to resolve such issues. 作为建议,您应该使用实现
try - catch
并在某处记录异常以便能够解决此类问题。
https://github.com/Rotimi-28/book-search-engine https://github.com/Rotimi-28/book-search-engine
Failed to load resource: the server responded with a status of 500 (Internal Server Error)加载资源失败:服务器响应状态为 500(内部服务器错误)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.