Been getting a "parsererror" from jquery for an Ajax request, I have tried changing the POST to a GET, returning the data in a few different ways (creating classes, etc.) but I cant seem to figure out what the problem is.
(我一直在从jquery收到针对Ajax请求的“ parsererror”,我尝试将POST更改为GET,以几种不同的方式(创建类等)返回数据,但我似乎无法弄清楚问题出在哪里。)
My project is in MVC3 and I'm using jQuery 1.5 I have a Dropdown and on the onchange event I fire off a call to get some data based on what was selected.
(我的项目在MVC3中,我使用的是jQuery 1.5,我有一个Dropdown,并且在onchange事件上,我触发了一个调用,以根据所选内容获取一些数据。)
Dropdown: (this loads the "Views" from the list in the Viewbag and firing the event works fine)
(下拉列表:(这会从Viewbag的列表中加载“ Views”,并触发事件可以正常进行))
@{
var viewHtmls = new Dictionary<string, object>();
viewHtmls.Add("data-bind", "value: ViewID");
viewHtmls.Add("onchange", "javascript:PageModel.LoadViewContentNames()");
}
@Html.DropDownList("view", (List<SelectListItem>)ViewBag.Views, viewHtmls)
Javascript:
(Javascript:)
this.LoadViewContentNames = function () {
$.ajax({
url: '/Admin/Ajax/GetViewContentNames',
type: 'POST',
dataType: 'json',
data: { viewID: $("#view").val() },
success: function (data) {
alert(data);
},
error: function (data) {
debugger;
alert("Error");
}
});
};
The above code successfully calls the MVC method and returns:
(上面的代码成功调用了MVC方法并返回:)
[{"ViewContentID":1,"Name":"TopContent","Note":"Content on the top"},
{"ViewContentID":2,"Name":"BottomContent","Note":"Content on the bottom"}]
But jquery fires the error event for the $.ajax() method saying "parsererror".
(但是jquery触发$ .ajax()方法的错误事件,提示“ parsererror”。)
ask by dkarzon translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…