jquery ajax 200 OK JSON.ParseError [英] jquery ajax 200 OK JSON.ParseError
问题描述
我有一个控件,其中有一个文本框,当其内容更改时,它将欺骗此javascript函数:
I have a control which has a textbox which, when its content changes, will tricker this javascript function:
page
参数为document.URL
,因为该控件没有附加的.asxc页,而fieldValue
是文本框的值.
page
parameter is document.URL
as the control has no attached .asxc page and fieldValue
is value of the textbox.
function UpdateFieldsOnListSelection(page, fieldValue) {
$.ajax({
type: "POST",
url: page + "/IsSelectedListPictureLibrary",
data: { "libraryInfo": fieldValue },
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert("Success!");
},
error: function (jqXHR, textStatus, errorThrown) {
alert("jqXHR: " + jqXHR.status + "\ntextStatus: " + textStatus + "\nerrorThrown: " + errorThrown);
}
});
};
它不断抛出此错误:
jqXHR:200
textStatus:parsererror
errorThrown:SyntaxError:JSON.parse:意外字符
jqXHR: 200
textStatus: parsererror
errorThrown: SyntaxError: JSON.parse: unexpected character
IsSelectedListPictureLibrary
的代码:
[WebMethod]
public static bool IsSelectedListPictureLibrary(string libraryInfo)
{
if (string.IsNullOrEmpty(libraryInfo)) return false;
var common = new Utility();
var storedLibraryInfo = common.GetStoredLibraryInfo(libraryInfo);
if (storedLibraryInfo == null) return false;
var web = SPContext.Current.Site.OpenWeb(storedLibraryInfo.WebId);
var spList = web.Lists[storedLibraryInfo.LibraryId];
if (spList.BaseTemplate == SPListTemplateType.PictureLibrary)
{
web.Dispose();
return true;
}
web.Dispose();
return false;
}
我尝试将ajax中的json
更改为jsonp
,但是发生了相同的错误.
我尝试更改data
的格式.
I have tried changing json
in the ajax to jsonp
, but same error occured.
I tried changing the format of data
.
有什么想法吗?
推荐答案
尝试从Ajax参数中删除contentType
和dataType
并自动识别它们
Try to remove contentType
and dataType
from Ajax parameters and let them be identified automatically
这篇关于jquery ajax 200 OK JSON.ParseError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!