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条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥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之后自动重连失效