我可以在不使用AJAX的情况下发布JSON吗? [英] Can I post JSON without using AJAX?

查看:117
本文介绍了我可以在不使用AJAX的情况下发布JSON吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些数据,让我们说:

I have some data, lets say:

var dat = JSON.stringify(frm.serializeArray())

我想使用往返(又名非ajax)将其提交给服务器。

I want to submit this to the server using a roundtrip (aka, non ajax).

我知道这是可能的,但我找不到任何关于它的文献。想法?

I know this is possible, but I can't find any literature on it. Ideas?

(我正在使用jQuery,如果这更容易)

(I am using jQuery, if that makes it easier)

编辑:所有这些答案到目前为止回答这个问题,我应该包括我想要一个内容类型的application / json

while all of these answers so far answer the question, I should have included that I want an "content type" of "application/json"

推荐答案


  1. 创建具有唯一id属性的HTML表单。您可以使用CSSdisplay:none隐藏它。同时填写操作和方法属性。

  2. 添加文本隐藏输入表单的字段。确保给它一个有意义的名称属性。这就是服务器获取数据的名称。

  3. 使用JQuery(或普通的旧javascript)将变量dat复制到输入字段中

  4. 使用脚本提交表单

  1. Create an HTML form with unique "id" attribute. You can hide it using CSS "display:none". Also fill the action and method attributes.
  2. Add a text or hidden input field to the form. make sure you give it a meaningful "name" attribute. That's the name that the server would get the data within.
  3. Using JQuery (or plain old javascript) copy the variable "dat" into the input field
  4. Submit the form using script

这篇关于我可以在不使用AJAX的情况下发布JSON吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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