我有一个控件,它有一个文本框,当它的内容发生变化时,它会欺骗这个 javascript 函数:
page
参数是document.URL
因为控件没有附加的 .asxc 页面并且fieldValue
是文本框的值。
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:意外字符
代码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;
}
我尝试将json
ajax 更改为jsonp
,但发生了同样的错误。
我尝试更改data
.
有任何想法吗?