读书人

mvc过去台发送ajax请求得到的数据显示

发布时间: 2012-10-23 12:12:22 作者: rapoo

mvc从前台发送ajax请求得到的数据显示未定义(undefined),哪位帮忙看看
前台代码是这样的:
var categoryId = $(this).attr("title");
var datas = $.ajax({
type: "POST",
sysnc: true,
url: "GetDocumentByCategoryId",
data: "CategoryId=" + categoryId,
dataType: "json"
}).responseText;
alert(datas);
[size=16px][/size]

后台代码:
public JsonResult GetDocumentByCategoryId(int categoryId)
{
List<Document> documents = DocumentService.GetDocumentByCategory(categoryId);
return Json(documents);
}
调试显示已经成功从数据库中取到数据了!
但是在前台调用时显示未定义,哪位帮我看看!!!

[解决办法]
首先你断点打了进入后台controller了吧.如果进了然后他也成功返回了你说的哪个前台对象是undefined,
其次

HTML code
'HTML'        var AjaxRefresh = function () {            $.ajax({                url: "/Test/TestAjaxFresh",                dataType: "json",                type: "post",                success: function (result) {                    $("#firstDiv").html(result.data);                }            })        }
[解决办法]
试试这样
JScript code
var categoryId = $(this).attr("title");$.post("GetDocumentByCategoryId",{CategoryId:categoryId},function(data){  alert(datas);}); 

读书人网 >asp.net

热点推荐