开发者

$.post in json format using a variable to store the json string?

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 won开发者_开发问答t work? Or how can it be done?


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


$.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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜