jquery ajax 200 OK JSON.ParseError

编程入门 行业动态 更新时间:2024-10-24 16:33:03
本文介绍了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

本文发布于:2023-10-30 22:33:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1544200.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ajax   jquery   ParseError   JSON

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!