$.post 以 json 格式使用变量来存储 json 字符串?

发布于 2024-09-12 08:25:11 字数 1012 浏览 5 评论 0原文

我需要发布 60 个输入。我已经构建了 json 字符串并将其存储在变量中。但不幸的是,以下代码不起作用:

$.post("process_form.php", my_var);

my_var 包含格式如下的 json 字符串:

{ starta:'1', currenta:'5', finisha:'2', startb:'1', currentb:'5', finishb:'2', startc:'1', currentc:'5', finishc:'2', startd:'1', currentd:'5', finishd:'2', starte:'1', currente:'5', finishe:'2', startf:'1', currentf:'5', finishf:'2', startg:'1', currentg:'5', finishg:'2', starth:'1', currenth:'5', finishh:'2', starti:'1', currenti:'5', finishi:'2', startj:'1', currentj:'5', finishj:'2', startk:'1', currentk:'5', finishk:'2', startl:'1', currentl:'5', finishl:'2', startm:'1', currentm:'5', finishm:'2', startn:'1', currentn:'5', finishn:'2', starto:'1', currento:'5', finisho:'2', startp:'1', currentp:'5', finishp:'2', startq:'1', currentq:'5', finishq:'2', startr:'1', currentr:'5', finishr:'2', starts:'1', currents:'5', finishs:'2', startt:'1', currentt:'5', finisht:'2' }

有什么想法为什么这不起作用?或者说怎样才能做到呢?

I need to post 60 inputs. I have built up the json string and stored it in a variable. But unfortunately the following code doesnt work:

$.post("process_form.php", my_var);

my_var contains a json string in the format:

{ starta:'1', currenta:'5', finisha:'2', startb:'1', currentb:'5', finishb:'2', startc:'1', currentc:'5', finishc:'2', startd:'1', currentd:'5', finishd:'2', starte:'1', currente:'5', finishe:'2', startf:'1', currentf:'5', finishf:'2', startg:'1', currentg:'5', finishg:'2', starth:'1', currenth:'5', finishh:'2', starti:'1', currenti:'5', finishi:'2', startj:'1', currentj:'5', finishj:'2', startk:'1', currentk:'5', finishk:'2', startl:'1', currentl:'5', finishl:'2', startm:'1', currentm:'5', finishm:'2', startn:'1', currentn:'5', finishn:'2', starto:'1', currento:'5', finisho:'2', startp:'1', currentp:'5', finishp:'2', startq:'1', currentq:'5', finishq:'2', startr:'1', currentr:'5', finishr:'2', starts:'1', currents:'5', finishs:'2', startt:'1', currentt:'5', finisht:'2' }

Any ideas why this wont work? Or how can it be done?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

z祗昰~ 2024-09-19 08:25:11

尝试在键和值两侧使用双引号。

使用它来测试 JSON 是否有效:
http://json.parser.online.fr/

或者只使用 jQuery 序列化方法

Try using double quotes around both the key and the value.

Use this to test that the JSON is valid:
http://json.parser.online.fr/

or just use the jQuery serialize method

生活了然无味 2024-09-19 08:25:11
$.post('lol', { starta:'1', currenta:'5', finisha:'2', startb:'1', currentb:'5', finishb:'2', startc:'1', currentc:'5', finishc:'2', startd:'1', currentd:'5', finishd:'2', starte:'1', currente:'5', finishe:'2', startf:'1', currentf:'5', finishf:'2', startg:'1', currentg:'5', finishg:'2', starth:'1', currenth:'5', finishh:'2', starti:'1', currenti:'5', finishi:'2', startj:'1', currentj:'5', finishj:'2', startk:'1', currentk:'5', finishk:'2', startl:'1', currentl:'5', finishl:'2', startm:'1', currentm:'5', finishm:'2', startn:'1', currentn:'5', finishn:'2', starto:'1', currento:'5', finisho:'2', startp:'1', currentp:'5', finishp:'2', startq:'1', currentq:'5', finishq:'2', startr:'1', currentr:'5', finishr:'2', starts:'1', currents:'5', finishs:'2', startt:'1', currentt:'5', finisht:'2' } )

上面的代码工作正常,并且可以正确发布适合我的数据。提供更多信息怎么样?

$.post('lol', { starta:'1', currenta:'5', finisha:'2', startb:'1', currentb:'5', finishb:'2', startc:'1', currentc:'5', finishc:'2', startd:'1', currentd:'5', finishd:'2', starte:'1', currente:'5', finishe:'2', startf:'1', currentf:'5', finishf:'2', startg:'1', currentg:'5', finishg:'2', starth:'1', currenth:'5', finishh:'2', starti:'1', currenti:'5', finishi:'2', startj:'1', currentj:'5', finishj:'2', startk:'1', currentk:'5', finishk:'2', startl:'1', currentl:'5', finishl:'2', startm:'1', currentm:'5', finishm:'2', startn:'1', currentn:'5', finishn:'2', starto:'1', currento:'5', finisho:'2', startp:'1', currentp:'5', finishp:'2', startq:'1', currentq:'5', finishq:'2', startr:'1', currentr:'5', finishr:'2', starts:'1', currents:'5', finishs:'2', startt:'1', currentt:'5', finisht:'2' } )

The code above works fine and POSTS properly with the right data for me. How about providing more info?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文