提交形式JSON(没有AJAX) [英] Submit a form as JSON (no AJAX)

查看:114
本文介绍了提交形式JSON(没有AJAX)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能提交表单数据作为JSON,而无需使用AJAX?

Is it possible to submit form data as JSON, without using AJAX?

我试着改变加密类型:

<form enctype="application/json"></form>

但是,这不是根据对W3Schools的有效值

我想这种现象的原因是,请求的URL会返回一个文件,我显然不能做,如果我使用AJAX什么。我想送标记为 JSON数据内容类型:应用程序/ JSON 使ASP.NET MVC将使用JSON结合

The reason I would like this behaviour is that the requested URL will return a file, which I obviously can't do anything with if I use AJAX. I would like to send JSON data marked as Content-Type: application/json so that ASP.NET MVC will use its JSON binding.

推荐答案

你能使用JSON.stringify()来序列化客户端对象,然后东西,变成一个隐藏的输入并提交您的形式......然后在控制器侧将其背出的Request.Form和反序列化它到你的对象吗?

Could you use JSON.stringify() to serialize your client side object and then stuff that into a hidden input and submit your form...and then in the controller side pull it back out of the Request.Form and deserialize it into your object?


只是在原来的问题下方的注释部分,这基本上是一个重复的帖子看到的和这的计算器工作作为解决方案。

这篇关于提交形式JSON(没有AJAX)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆