dongwen7730 2014-10-02 16:38
浏览 41
已采纳

在使用.each制定选项时,无法使用$ .post请求读取$ _POST值

Formulated my options string using .each and sending it via .post to an external script.

        clicked.closest("form").find("input,textarea").each(function(){
            var input=$(this);
            if(index==1){
                options = "{"+input.attr("name")+":'"+input.val()+"'";
            }else if(index==no_inputs){
                options += ","+input.attr("name")+":'"+input.val()+"'}";
            }else{
                options += ","+input.attr("name")+":'"+input.val()+"'";
            }
            index++;
        });
        alert(options);
        $.post('../pages/ajax/add_orders.php',options,function(data){
            alert(data);
        });

..problem is when my php call script is..

    <?php
        print_r($_POST);
    ?>

I simply get an empty array with no values.

The first alert shows the formulated string correctly.

But the second one returns an empty value.

Any help greatly appreciated.

  • 写回答

2条回答 默认 最新

  • doushao5047 2014-10-02 16:55
    关注

    You're post needs to be an actual object, you're creating a string.

        clicked.closest("form").find("input,textarea").each(function(){
            var input=$(this);
            if(index==1){
                options[input.attr("name")] = input.val();
            }else if(index==no_inputs){
                options[input.attr("name")] = input.val();
            }else{
                options[input.attr("name")] = input.val();
            }
            index++;
        });
    

    I think the above way will work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料