dtdfj08626 2018-11-08 20:44 采纳率: 0%
浏览 45
已采纳

协助在html表单上传递json对象

Hello I have a multidimensional associative array I want to be able to send forward using POST on an html form. I thought this would be a simple matter but I think I am missing something.

here is where i encode the array into json:

$bottomInfoJson=json_encode($bottomInfo);

print_r($bottomInfoJson);

Just to show the json was properly encoded I printed it out and this is what i got:

 {
 "M1":{"amount":765,"instMrn":"100"},
"M2":{"amount":50,"instMrn":"100"},
"M3":{"amount":770,"instMrn":"100"},
"M4":{"amount":2159,"instMrn":"100"},
"M5":{"amount":145,"instMrn":"100"},
"M6":{"amount":500,"instMrn":"100"},
"M7":{"amount":7507,"instMrn":"100"},
"M8":{"amount":335,"instMrn":"100"},
"M9":{"amount":525,"instMrn":"100"},
"C10":{"amount":130,"instMrn":"100"}}

So I thought I could just pass this on a form simply since it is contained in the php variable...

Here is my form:

<form method='post' action="midMichSummary" enctype='application/json'>
<input type="hidden" name="sdate" value="<?php echo $sdate; ?>"/>

<input type="hidden" name="hbpb" value="<?php echo $hbpb; ?>"/>
<input type="hidden" name="bottomInfoJson" value="<?php echo $bottomInfoJson; ?>" />

<input type="submit" value="Summary->"/>

</form>

Basically all stuff is being passed fine except the json array - using print-r($_POST) at the destination shows me what has been passed...

So I am thinking there may be something additional i need to do to pass this properly - so I am hoping someone can help with this...

  • 写回答

1条回答 默认 最新

  • duandeng7132 2018-11-08 21:18
    关注

    I don't know what you get exactly in the $_POST["bottomInfoJson"] variable, but in case you got something like this "{", then the issue should be in the double quotation, you can simply try replacing the double quotation here:

    value="<?php echo $bottomInfoJson; ?>"
    

    with single quotation

    value='<?php echo $bottomInfoJson; ?>'
    

    It should work

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改