内部服务器错误#500,而试图与jQuery Ajax和MVC显示JSONResult [英] Internal Server Error #500 while trying to display JSONResult with jQuery ajax and MVC

查看:293
本文介绍了内部服务器错误#500,而试图与jQuery Ajax和MVC显示JSONResult的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

控制器

public JsonResult TeamInfo(string teamName)
            {
                teamDA = new TeamDataAccess();
                var teamInfo = teamDA.TeamInfo(teamName);
               System.Web.Script.Serialization.JavaScriptSerializer oSerializer =
             new System.Web.Script.Serialization.JavaScriptSerializer();
                string sJSON = oSerializer.Serialize(teamInfo);
                JsonResult jsonResult 
=new JsonResult(){ JsonRequestBehavior = JsonRequestBehavior.AllowGet }; 
                    jsonResult.Data = sJSON; // first i give this.
         jsonResult.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
                    return jsonResult;
                }

这是jQuery的呼叫控制器

Calling Controller from jQuery

$.ajax({
                url: 'Team/TeamInfo/' + teamName,
                success: function (data) {
                    $('#teamDetails').html(data);
                    alert('Load was performed.');
                    $("#dialog-modal").dialog("open");
                }
            });

在调试我可以看到它正在执行,直到在控制器中的最后一行返回jsonResult; 警报('进行装载。'); 是不可见的。
你知道什么是它不进入成功的部分原因。有在服务器侧没有错误。任何帮助高度AP preciated。

While debugging I can see it is executing till the last line in controller return jsonResult; But alert('Load was performed.'); is not visible. Do you know what is the reason it is not going into success part. There is no error in server side. Any help is highly appreciated.

修改
当我加入Ajax调用的错误。它说,错误500(内部服务器错误)。如何找到这个问题?

EDIT When I added the error in ajax call. it says error 500 (internal server error). How do I find this issue ?

推荐答案

您不必让所有的序列化的东西用的JavaScriptSerializer。

You don't need to make all the serialization stuff with JavaScriptSerializer.

您的操作方法可能看起来是这样:

Your action method could look like this:

 public JsonResult TeamInfo(string teamName)
 {
      return Json(new TeamDataAccess()TeamInfo(teamName), JsonRequestBehavior.AllowGet); 
 }

这篇关于内部服务器错误#500,而试图与jQuery Ajax和MVC显示JSONResult的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆