POST表单数据作为application/json [英] POST form data as application/json

查看:835
本文介绍了POST表单数据作为application/json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个API,该API接收一个应用程序/json发布请求,并触发一些流程.

I'm working on an API that receives an application/json post request, and triggers some flow.

此刻我的主要问题是发送一个application/json帖子,其中包含来自输​​入表单的数据.

My main issue at the moment is sending an application/json post, with data from a input form.

我已经尝试了jQuery ajax(),但是由于我期望重新加载页面,因此它似乎无法按需工作.

I've tried jQuery ajax () but since I'm expecting a page reload it doesn't seem to be working as needed.

由于这不是非常复杂的应用程序的一部分,所以我需要做的就是能够采用非常简单的形式并将其内容发布到json对象中,并按照上述application/json请求进行发送

Since this isn't part off a very complex app all I need to do is be able to take a very simple form and post it's contents into a json object and send it as the mentioned application/json request

推荐答案

这是不可能的.

JSON不是表单支持的编码格式,发出POST请求的唯一其他方法是使用XMLHttpRequest.

JSON is not a supported encoding format for forms and the only other way to make a POST request is to use XMLHttpRequest.

您最好的选择是调整API,使其支持application/x-www-form-urlencoded编码数据.

Your best bet is to adjust the API so it supports application/x-www-form-urlencoded encoded data.

或者,您可以发出Ajax请求,将数据存储在服务器上的临时数据存储中,然后返回标识令牌,然后使用location =将浏览器重定向到包含该令牌的URL,以便呈现页面从它.

Alternatively, you can make an Ajax request, store the data in a temporary data store on the server and return an identifying token and then use location = to redirect the browser to a URL including that token so you can render the page from it.

这篇关于POST表单数据作为application/json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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