【问题标题】:Internal Server Error 500 on AJAX requestAJAX 请求的内部服务器错误 500
【发布时间】:2015-07-22 08:38:54
【问题描述】:

我收到“内部服务器错误 500”。

我无法点击操作,当我检查元素时它给出“内部服务器错误 500”。

它在本地运行良好,但是当我在客户端服务器上部署/发布它时,它不会点击 URL。

我不知道出了什么问题。

这是我的 AJAX:

    jQuery2(document).ready(function () {
        jQuery2('#fileupload').fileupload({

            dataType: 'json',
            type: "POST",
            url: '@Url.Action("UploadExcelFile", "PurchaseOrder")',
            contentType: "application/json; charset=utf-8",
            autoUpload: true,
            done: function (e, data) {
               jQuery2('#filepath').val(data.result.FileName);
            },

            error: function (e, data) {
                                        
                alert(e.error);
            }
     
        });
    });

这是控制器动作

   [HttpPost]
        public ContentResult UploadExcelFile(string filepath, LapTopDetail REC)
        {
            //var fileSavePath="";
            DataTable dt_Excel_Data = null;
            string savedFilePath = "";
            string FileName = "";
            int count = 0;
            try
            {
                foreach (string file in Request.Files)
                {
                    HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase;
                    if (hpf.ContentLength == 0)
                        continue;
                    savedFilePath = Path.Combine(Server.MapPath("~/Attachments/LapTopDetailFiles/"), Path.GetFileName(hpf.FileName));
                    FileName = hpf.FileName;
                    hpf.SaveAs(savedFilePath); // Save the fil
                }
                BllClsPurhcaseOrder objclsPO = new BllClsPurhcaseOrder();

                FileStream stream = System.IO.File.Open(savedFilePath, FileMode.Open, FileAccess.Read);

                IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
                DataSet result = excelReader.AsDataSet();
                excelReader.IsFirstRowAsColumnNames = true;
                DataSet resultDs = excelReader.AsDataSet();
                SetTargetPriceDT REC_DT = new SetTargetPriceDT();
                DataTable dt = new DataTable();
                dt_Excel_Data = resultDs.Tables[0];

                              if (dt_Excel_Data.Rows.Count > 0)
                {
                    int intCondition = 9;
                    int POID = Convert.ToInt32(REC.PO_ID);

                    count = objclsPO.SaveTempExcelFile(intCondition, POID, dt_Excel_Data);
                }
                return Content("{\"FileName\":\"" + FileName + "\",\"RowsEffected\":\"" + count + "\",\"Item_Original_SrNo\":\"" + string.Format("{0} bytes", count) + "\"}", "application/json");

            }
            catch (Exception ex)
            {

             return Content("{\"FileName\":\"" + ex.Message + "\",\"RowsEffected\":\"" + count + "\",\"Item_Original_SrNo\":\"" + string.Format("{0} bytes", count) + "\"}", "application/json");

            }

        }

【问题讨论】:

  • 使用error: function (jqXHR,errorResponse,error) {console.log(jqXHR.responseText);}记录您遇到的错误并告诉我!
  • 返回 HTTP 错误 404.0 - Not Found 您要查找的资源已被删除、更改名称或暂时不可用。
  • 这意味着 url 没有找到...做一件事将您的 url 更改为正常的 url: '/PurchaseOrder/UploadExcelFile', 并将 dataType 更改为 text 而不是 json

标签: ajax asp.net-mvc-4


【解决方案1】:

我终于找到了解决办法..

我的客户端服务器上存在 Ajax 权限问题.. 写权限被禁用,所以我检查了写权限,现在 它的工作正常

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-19
    • 1970-01-01
    • 1970-01-01
    • 2019-06-05
    • 1970-01-01
    • 2019-06-26
    • 2015-09-20
    相关资源
    最近更新 更多