I have a control that has a text box that when changing its contents will trick this javascript function:
page parameter document.URL because the control does not have an attached page .asxc and fieldValue is the value of the text field.
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); } }); };
He continues to throw this error:
jqXHR: 200
textStatus: parsererror
errorThrown: SyntaxError: JSON.parse: unexpected character
IsSelectedListPictureLibrary Code:
[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; }
I tried changing json in ajax to jsonp , but the same error occurred.
I tried changing the data format.
Any ideas?
source share