从jquery获取Ajax请求的"parsererror",我尝试将POST更改为GET,以几种不同的方式返回数据(创建类等),但我似乎无法弄清问题是什么.
我的项目在MVC3中,我正在使用jQuery 1.5我有一个Dropdown,在onchange事件中,我根据所选内容启动调用以获取一些数据.
下拉列表:(这会从Viewbag中的列表中加载"视图"并触发事件正常工作)
@{
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)
Run Code Online (Sandbox Code Playgroud)
使用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");
}
});
};
Run Code Online (Sandbox Code Playgroud)
上面的代码成功调用了MVC方法并返回:
[{"ViewContentID":1,"Name":"TopContent","Note":"Content on the top"},
{"ViewContentID":2,"Name":"BottomContent","Note":"Content on the bottom"}]
Run Code Online (Sandbox Code Playgroud)
但是jquery会触发$ .ajax()方法的错误事件,说"parsererror".
我正在制作一个需要以JSONP格式返回数据的Web服务.我正在使用JSON taglib用于JSP,我认为所有必须添加的都是括号,但我找不到一个好的资源来验证这一点.
例如,使用此函数返回Web服务函数:
private static String getJSONPObject(String s) throws JSONException {
return "(" + new JSONObject(s) + ")";
}
Run Code Online (Sandbox Code Playgroud)
它是否正确?
谢谢!
当我升级到jQuery 1.5.1(或1.5)时ajax()
,我站点中的所有调用都会在错误选项函数中生成"parserror".还有一个脚本错误
Uncaught SyntaxError: Unexpected token : jquery-1.5.1.min.js:16
Run Code Online (Sandbox Code Playgroud)
使用1.4.4,该站点一直在运行w/o错误.这是来自其中一个ajax()调用的代码.
$.ajax({
url: '/CustomerGroup/Get',
type: 'POST',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (grp) {
if (grp != null) {
clear();
group = grp;
load(grp);
} else{
showError(
'Customer Group',
'Whoops, error getting customer group information. Please contact support@myorg.com and include your username and date/time of the error.'
);
}
},
error: function (x,s,e) {
showError(
'Customer Group',
'Whoops, error getting customer group information. Please contact support@myorg.com and include your …
Run Code Online (Sandbox Code Playgroud) jquery ×2
json ×2
asp.net ×1
c# ×1
java ×1
javascript ×1
jsonp ×1
parse-error ×1
web-services ×1