douzhai7873 2017-03-20 08:21
浏览 127

通过JQuery $ .ajax将多个JavaScript对象传递给PHP

I have a object recipe that has multiple params

This works, I passed the object thru ajax to my php

 $.post('addRecipe.php', recipe,  function () {});

And this works, php getting the params

function getParam($param) {
    if (!empty($_POST[$param])) {
        return $_POST[$param];
    }
    return 'UNKNOWN';
}

$name = getParam('name');
$phone = getParam('phone');

Now I want to pass 2 objects the recipe that has multiple params and recipeID that has 1 param

  $.post('editRecipe.php', {recipe: recipe, recipeID: recipeID},  function (){});

how can i get it with php?

  • 写回答

2条回答 默认 最新

  • douzhao5656 2017-03-20 08:29
    关注

    Just add another parameter with a different key. Pass it to the function from the post valur. Like you're already doing with recipe

    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮