我有一个控件,其中有一个文本框,当其内容更改时,它将欺骗此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
发布评论