douyunjiaok300404 2017-11-07 22:01
浏览 117
已采纳

PHP使用json stringify对象[关闭]

I have an object in the frontend and need to pass this value to the backend (PHP).

Frontend:

var cfg = {"tooltips":true,"tooltipTemplate":"<div></div>"},
jsonCfg = JSON.stringify(cfg);
$inputConfig.val(jsonCfg);
$form.submit();

Backend:

$config = $_POST['config'];
$json = json_decode($config);
echo $json->tooltips;
echo $json->tooltipTemplate;

The last string gives me only empty value, if I remove the first tag "<", I will get only "div>", but I do not understand how to prevent this behavior, I need any string without filtering or formatting.

  • 写回答

1条回答 默认 最新

  • dth62818 2017-11-07 22:05
    关注

    Your problem is simply, that <div></div> isn't visible in the browser. If you want to view the correct output, have a look at the page source or use htmlentities to escape the html tags.

    $config = $_POST['config'];
    $json = json_decode($config);
    echo $json->tooltips;
    echo htmlentities($json->tooltipTemplate);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化