weixin_33709364 2016-12-05 23:00 采纳率: 0%
浏览 29

回声发布Ajax数据

I am using AJAX to post some array data to the server. I get the following expected results in the Firebug network console from the Ajax request.

            POST -----> http://example.com/drag_data.php                
            //request header
                Host: example.com
                User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0
                Accept: */*
                Accept-Language: en-US,en;q=0.5
                Accept-Encoding: gzip, deflate
                Referer: http://example.com/drag.php
                Content-Type: application/x-www-form-urlencoded; charset=UTF-8
                X-Requested-With: XMLHttpRequest
                Content-Length: 90
                Cookie: PHPSESSID=b1lr9he4l2hbcnlkcsebfq2134
                Connection: keep-alive

            //data in the request body
                item[]=1&item[]=3&item[]=2&item[]=4&item[]=5

            //firebug params 
                 item[]:"1"
                 item[]:"3"
                 item[]:"2"
                 item[]:"4"
                 item[]:"5"

for infor this is the ajax call which give the expected success message (same as the firebug param output)

       $.post({

        data: data,

         type: 'POST',

        url: 'drag_data.php?',

        success:function(result){
        $(".result").html(data);},

        error: function(){
        console.log(arguments);
        }
    });

I just want to echo the posted data in the drag_data.php script. I have tried the following test code (as well as (print_r and var_dump) but cannot see any posted data which has baffled me. Can anyone tell me what I am doing wrong please?

drag_data.php test file

                $i = 0;

                //this loop is failing to echo the posted array data from the Ajax request
                foreach ($_POST['item'] as $value) {
                    echo "each".$value;
                    $i++;
                }
                ?>
  • 写回答

2条回答 默认 最新

  • weixin_33725807 2016-12-05 23:23
    关注
    1. Make url: '/drag_data.php', with preceding slash and without ?.
    2. Maybe serializing will help: make data: JSON.stringify(data) on client and json_decode on server.
    3. Check configurations of your server - are requests you're seeing in your firebug actually reaching the server?
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记