weixin_33716154 2019-02-04 05:53 采纳率: 0%
浏览 14

通过PHP处理AJAX数据

I have sent data using AJAX. I have used this code. I can handle & recive productInfo:JSON data using PHP but can't be handling datastring. Because showing like below image. How can handle or receive datastring using PHP? enter image description here

var datastring = jQuery("#chackOutBillingIfor").serialize();
jQuery.ajax({
      url: "/wp-admin/admin-ajax.php?action=chackOut",  
      data: {
              productInfo:JSON.stringify(cart), 
              billingInfo:JSON.stringify(datastring),
            },
      type: 'POST',
      cache: false,
})
  • 写回答

1条回答 默认 最新

  • weixin_33697898 2019-02-04 12:47
    关注

    You can split the billingInfo string on the & to get a list of key and value strings and then split those strings on =. The following function should be sufficient to return an array from the value.

    function stringToArray($str)
    {
        $result = array();
        foreach (explode('&', $str) as $pair) {
            list ($key, $val) = explode('=', $pair);
            $result[$key] = $val;
        }
        return empty($result) ? false : $result;
    }
    

    You may want to perform a check that the string contains at least one = and it cannot be in first position before processing the string.

    评论

报告相同问题?

悬赏问题

  • ¥15 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真