2014-10-02 116 views
-1

我有一個Ajax調用迴應:在家庭控制器無法加載資源的服務器用的500狀態(內部服務器錯誤)

$.ajax({ 
     url: '@Url.Action("LoadCategory", "Home")', 
     type: 'GET', 
     contentType: "application/json; charset=utf-8", 
     data: { fstValue: modelDDLValue }, 
     success: function (result) { 
      // do something here 
     }); 

和行動方法:

public JsonResult LoadCategory(string fstValue) 
{ 
     int modelId = 0; 
     if (fstValue != "") 
      modelId = Convert.ToInt32(fstValue); 

     var result = unitOfWork.CategoryRepository.GetCategoriesForModel(modelId); 

     string listUL = "<ul class=\"root\">"; 

     IList<SelectListItem> Data = new List<SelectListItem>(); 
     foreach (Category cat in result) 
     { 
      listUL += "<li><a class='parent' href=\"javascript:void()\">" + cat.CategoryNameEng + "<span class=\"value\">" + cat.Id.ToString() + "</span></a>"; 
      Data.Add(new SelectListItem() 
      { 
       Text = cat.CategoryNameEng, 
       Value = cat.Id.ToString(), 
      }); 

      if (cat.SubCategories.Count() > 0) 
      { 
       listUL += "<ul class=\"l1\">"; 
       foreach (SubCategory scat in cat.SubCategories.Where(s => s.ModelId == modelId).ToList()) 
       { 
        listUL += "<li><a class='sub' href=\"javascript:void()\">" + scat.SubCategoryNameEng + "<span class=\"value\">" + "S" + scat.Id.ToString() + "</span></a></li>"; 
        Data.Add(new SelectListItem() 
        { 
         Text = scat.SubCategoryNameEng, 
         Value = "S" + scat.Id.ToString(), 
        }); 
       } 
       listUL += "</ul>"; 
      } 
      listUL += "</li>"; 
     } 
     listUL += "</ul>"; 

     // add listUL into Data as the last element 
     Data.Add(new SelectListItem() { Value = "listUL", Text = listUL }); 

    return Json(Data, JsonRequestBehavior.AllowGet); 
} 

但在虛擬主機提供商「我總是收到錯誤」無法加載服務器響應的狀態爲500(內部服務器錯誤)的資源「。

我試圖用$ .get()和其他東西替換ajax方法,在stackoverflow中閱讀關於此主題的所有答案,但沒有運氣。

我該如何處理?提前感謝!

+0

您的操作方法可能會受到影響。設置一箇中斷點並檢查它。 AJAX調用可能不是問題。相反,請調試這裏沒有提供的一段代碼,即'//這裏是一些邏輯'。 – 2014-10-02 08:17:57

+0

500錯誤通常是控制器方法拋出異常的結果。 – 2014-10-02 08:18:55

+0

代碼在調試模式下運行良好,部署後只會在webhost上出現問題 – user2925794 2014-10-02 08:19:40

回答

相關問題