将对象返回到ajax调用时出现500错误

时间:2015-12-18 18:10:20

标签: asp.net-mvc model-view-controller asp.net-ajax

当我尝试将结果返回到我的ajax调用时,我收到错误。每次尝试返回数据时都会出现500错误。这是我的ajax电话: 当我试图将结果返回到我的ajax调用时,我收到错误。每次尝试返回数据时都会出现500错误。这是我的ajax电话:

$("#UserActivation").change(function () {
       var userID = $("#UserActivation").val();
       var searchPic;
       var planID = $("#planid").val();
       debugger;
       $.ajax({
           type: "GET",
           url: "/Home/GetUserImage",
           data: { userID: userID, type: 'Activation', planID: planID },
           dataType: "json",
           contentType: "application/json; charset=utf-8",
           success: function (response) {        
                    debugger;
                    alert(response);
           },
           error: function (xhr, ajaxOptions, thrownError){
                    debugger;
                    alert(xhr.responseText);
           },
           complete: function (a) {
                    // Handle the complete event
                    debugger;
                    alert("ajax completed ");
           }
       });
       return false;
});

我的控制器功能是:

[HttpGet]
public JsonResult GetUserImage(string userID, String type, string planID)
{
     if (userID != null && type != null && planID != null)
          SaveUser(planID, userID, type);
     DataSet ds = SQL_DB.ExecuteDataSet("SELECT * FROM [M_UserRegistration] where [ActiveFlag] = 1 and UserId='" + userID + "'");
     UserData userData = new UserData();
     if (ds.Tables[0].Rows.Count > 0)
     {                   
          userData.UserID = Convert.ToString(ds.Tables[0].Rows[0]["UserId"]);
          userData.UserImage = "../../Images/Users/" + Convert.ToString(ds.Tables[0].Rows[0]["UserImage"]);
          userData.UserName = Convert.ToString(ds.Tables[0].Rows[0]["UserFirstName"]) + " " + Convert.ToString(ds.Tables[0].Rows[0]["UserLastName"]);
      }
      return Json(userData);
}

ajax错误导致500错误。

1 个答案:

答案 0 :(得分:1)

您必须允许请求类型loglike <- function(phi,y) { v = phi*I + C vi = solve(v) loglike = -.5*(log(det(v)) + (t(y)%*%vi%*%y)) return(-loglike) } phi = 0 parm <- optim(par=phi,fn=loglike,y=y,NULL,hessian = TRUE, method="L-BFGS-B",lower=0,upper=1000) 的{​​{1}}数据,如下所示。希望这能解决你的问题。

json