我有一个控件,它有一个文本框,当它的内容发生变化时,会使这个
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: 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,但发生了同样的错误.
我尝试改变数据格式.
有任何想法吗?