简体   繁体   English

加载资源失败:服务器响应状态为 500(内部服务器错误)

[英]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()返回nullforeach将抛出您尚未处理的异常。

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.

相关问题 加载资源失败:服务器响应状态为500(内部服务器错误 - Failed to load resource: the server responded with a status of 500 (Internal Server Error Ajax 调用资源加载失败:服务器响应状态为 500(内部服务器错误) - Ajax call with a failed to load resource: the server response with a status 500 (internal server error) jQuery ajax调用将无法访问控制器:无法加载资源:服务器以状态500(内部服务器错误)响应 - Jquery ajax call wont access the controller: Failed to load resource: the server responded with a status of 500 (Internal Server Error) 无法加载资源:服务器响应状态为 500(内部服务器错误)Azure MVC - Failed to load resource: the server responded with a status of 500 (Internal Server Error) Azure MVC 加载资源失败:服务器响应状态为500(内部服务器错误)asp.net - Failed to load resource: the server responded with a status of 500 (Internal Server Error) asp.net 加载资源失败:服务器响应状态为 500(内部服务器错误),同时从控制器返回 base64 格式的图像 - Failed to load resource: the server responded with a status of 500 (Internal Server Error) while returning image in base64 format from controller Ajax 调用“加载资源失败:服务器响应状态为 500” - Ajax call with a 'failed to load resource : the server responded with a status of 500' 无法加载资源:服务器使用Ajax响应状态为500 - Failed to load resource: the server responded with a status of 500 using Ajax 错误:无法加载资源:服务器的状态为400(错误请求) - Error:Failed to load resource: the server responded with a status of 400 (Bad Request) 加载资源失败:服务器在 asp.net 内核中使用谷歌图表时响应状态为 500 () - Failed to load resource: the server responded with a status of 500 () while using google charts in asp.net core
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM