当我想用 ajax 更新我的值时,我在我的页面中使用编辑器我收到此错误:未捕获的类型错误:将循环结构转换为 JSON
这是我的观点:
@{
Layout = null;
}
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Edit</title>
<script type="text/javascript">
$(function () {
$("#editor").kendoEditor({
value: "@Html.Raw(Model.Content)"
});
$("#back").click(function () {
$.get('@Url.Action("Index", "Editor")', { siteId: "@ViewBag.SiteId", widgetId: "@Model.WidgetId" },
function (data) {
$("div[data-role='popup']").remove();
var indexContent = $(data).find("#content");
$(indexContent).fadeIn(101);
$("#content").replaceWith(indexContent);
});
});
var content = $("#editor").data("kendoEditor");
$("#save").click(function () {
var editor = {
Id: 1,
Content: content,
Title: 1,
};
$.ajax({
url: '@Url.Action("Update", "Editor")',
type: "POST",
contentType: "application/json charset=UTF-8",
dataType: "json",
data: JSON.stringify(editor),
});
});
});
</script>
</head>
<body>
<div id="editorContainer">
<div id="editorContent">
<input type="text" value="@Model.Title" style="width:300px" id="title"/>
<textarea id="editor" rows="10" cols="30" style="width: 740px; height: 440px">
</textarea>
</div>
</div>
<button id="save">ذخیره</button>
<button id="back">بازگشت</button>
</body>
</html>
在我看来,我使用 jquery ajax 发布值,但出现错误。