AJAX请求上的内部服务器错误500

时间:2015-07-22 08:38:55

标签: ajax asp.net-mvc-4

我收到“内部服务器错误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");

            }

        }

1 个答案:

答案 0 :(得分:0)

最后我找到了解决方案..

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