$.post 以 json 格式使用变量来存储 json 字符串?
我需要发布 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试在键和值两侧使用双引号。
使用它来测试 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
上面的代码工作正常,并且可以正确发布适合我的数据。提供更多信息怎么样?
The code above works fine and POSTS properly with the right data for me. How about providing more info?