- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将“contentTools”与 ASP.NET C# 网站一起使用。我正在尝试将修改后的 json 发送到服务器端以存储在数据库中。
我已经通过外部网络验证了 JSON,但这是我的代码。出于测试目的,我尝试使用从 ASP.NET 方法发回的字符串来调用警报。
window.onload = function () {
//ShowCurrentTime();
var FIXTURE_TOOLS, IMAGE_FIXTURE_TOOLS, LINK_FIXTURE_TOOLS, editor;
ContentTools.IMAGE_UPLOADER = ImageUploader.createImageUploader;
ContentTools.StylePalette.add([new ContentTools.Style('By-line', 'article__by-line', ['p']), new ContentTools.Style('Caption', 'article__caption', ['p']), new ContentTools.Style('Example', 'example', ['pre']), new ContentTools.Style('Example + Good', 'example--good', ['pre']), new ContentTools.Style('Example + Bad', 'example--bad', ['pre'])]);
editor = ContentTools.EditorApp.get();
editor.init('[data-editable], [data-fixture]', 'data-name');
editor.addEventListener('saved', function (ev) {
var name, payload, regions, xhr;
// Check that something changed
regions = ev.detail().regions;
if (Object.keys(regions).length == 0) {
return;
}
// Set the editor as busy while we save our changes
this.busy(true);
// Collect the contents of each region into a FormData instance
payload = new FormData();
payload.append('regions', JSON.stringify(regions));
xhr = new XMLHttpRequest();
xhr.open('POST', 'Default.aspx/getJSONHTMLResponse');
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
alert(xhr.responseText);
}
};
xhr.send(payload);
});
Here is my server-side:
[System.Web.Services.WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string getJSONHTMLResponse(string name)
{
return "Success";
}
这是我在 chrome 开发者工具中看到的请求负载:
------WebKitFormBoundaryilrxnMxm7ANdiYMp
Content-Disposition: form-data; name="regions"
{"para-1":"<p>\n testestest\n</p>","para-2":"<p>\n testestestestest.\n</p>"}
------WebKitFormBoundaryilrxnMxm7ANdiYMp--
错误:
{"Message":"Invalid JSON primitive: ------WebKitFormBoundaryilrxnMxm7ANdiYMp.","StackTrace":" at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject()\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String input)\r\n at System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext context, JavaScriptSerializer serializer)\r\n at System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData, HttpContext context)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.ArgumentException"}
最佳答案
因为您从 api 端点接受字符串作为参数,所以将其作为字符串发送。无需附加到 FormData 中。这会将您的有效负载作为对象发送。
xhr.send(JSON.stringify(regions));
关于javascript - ASP.NET JavaScript - 无效的 JSON 原语,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61282824/
我对 JS 还很陌生,目前正在学习对象,对原语有点困惑。在 W3schools 上,javascript 原语定义为: “原始值是没有属性或方法的值。 原始数据类型是具有原始值的数据。 JavaScr
我可以用 java 做这个吗? private static boolean isRight(){ return new Random.nextBolean(); } boolean test
OpenCV 原语是否基于 CUDA Nvidia 性能原语 (NPP)? 我所说的原语是指在 NPP 库中实现的相同原语,例如:boxFilter、Mirror、Convolution... 我想知
这个问题在这里已经有了答案: How many integers can I create in 1GB memory? (3 个答案) 关闭 6 年前。 引用自 Algorithms 4th ed
我正在尝试编写我的第一个显示三角形的 DirectX 10 程序。一切都编译得很好,渲染函数被调用,因为背景变成了黑色。但是,我尝试使用三角形 strip 基元绘制的三角形根本不显示。 初始化函数:
什么是 UI 原语? if you find yourself wishing that you had a different set of UI primitives to work with,
我知道这个问题已经在 Stakoverflow 中被问过多次。但是没有一个解决方案对我有帮助。谁能告诉我做错了什么 我有一个 Controller Action 如下 Function WF
我正在尝试从一个程序中读取一个二进制文件,该程序将日志(某种)写入一个dat文件,我已经很好地找到了使用Java的格式。我这样加载它: DataInputStream in = new DataInp
我有代码对 MVC Controller 方法进行 AJAX 调用,如果我这样做,它会顺利工作: var obj = '{"titlename":"whatever"}'; $
我有一个对象: class Data{ int a; int b; AtomicIntegerArray c = new AtomicIntegerArray(10000); }
我的应用程序具有以下 Javascript 原语: var bearerToken = "a"; var expirationDate = "b"; var firstName = "c"; var
我经常发现自己需要让组件接受任何有效的 HTML 属性以使底层 HTML 元素使用它们。 class Input extends React.Component { // Here I use o
我尝试使用 javascriptserializer 反序列化我的 json,但收到错误“无效的 json 原语” 其他帖子提到要验证 json,我也这样做了。 JavaScriptSerialize
有没有办法制作一个原语并反复使用它?例如:如果我制作一个立方体,我可以创建 100 个立方体并制作一个 10x10 的网格吗?我试过使用 for 循环并在每个循环中更新 x 和 z 坐标,但它只移动在
扩展和装箱 Java 原语。 我知道不可能将包装类从一个扩展到另一个,因为它们不是来自同一继承树。为什么不能将基元扩展为另一种基元类型并自动装箱扩展的基元? 鉴于可以将字节参数传递给需要 int 的方
你能帮我解决这个问题吗?我有一个 asp.net 应用程序,在此我使用 Javascript 序列化程序序列化数据集,然后转换为列表。该代码如下所示。 JavaScriptSerializer jso
好的,所以当我尝试运行我的应用程序时遇到这个问题: Invalid JSON primitive: . public static void ReloadConfig() { if (!Fil
我正在尝试通过以下 jQuery Ajax 调用将字符串化的 JSON 对象发送到 MVC 方法: $.ajax({ type: "POST", url:
当我在 C# 中使用 JavaScriptSerializer 时,出现“无效的 JSON 原语”异常。我假设问题出在我的 json 输入字符串上,但我没有看到问题。 JavaScriptSerial
我知道您可以直接从 Scala 访问 java 原语 val javaDouble = new java.lang.Double(1.0) 这是否意味着我们正在通过包装器或直接访问原语?语法 new
我是一名优秀的程序员,十分优秀!