weixin_33696106 2013-04-04 02:04 采纳率: 0%
浏览 20

PHP未收到POST字符串

I am trying to use the following function to post a single select option value to a pChart page. When I try to check the form data in developer tools it suggests the name:datastring pair is being posted to the PHP file. The Javascript file is as follows:

$(document).ready(function() {
    $('#players').on('change', function() {
        var dataString = $('#players option:selected').val();
        $.post("../pChart2.1.3/AllPillarsCoach.php",
               {name:dataString},
               "
Status: " + status);
    });
});

But it shows an empty array:

<?php
    echo "<pre>";
    var_dump($_POST)."br /";
    echo "</pre><br>";
    ...
?>

I have checked with GET as well with no success. I don't want a return to the browser as the PHP page renders an image and it doesn't appear too happy about being applied to a div.

Thanks for the replies so far my original, function was as follows which I truncated to try and make sure that the pChart was going to be parsed.

    $(document).ready(function() {
    $('#players').on('change', function() {
        var dataString = $('#players option:selected').val();
                $.post("../pChart2.1.3/All.php",{name:dataString},"
Status: " + status,
                    function(status){
                alert("Data: " + dataString + "\Status: " + status);
            });

            });

        });

The developer tools with both versions suggests that the form data is being posted name= thw17po14 and parsed name: thw17po14. The alert shows both the dataString and the success message. I just want to take the post data as criteria for a query and the resulting chart will be accessed separately so no need for a return to the browser. Alert as it stands now shows the following after changing the "select option", again thanks for any help in advance.

            Data: thw17po14Status: <pre>array(1){
                ["name"]=>
                  string(9)"thw17po14"
                     }
                   </pre><br>
  • 写回答

2条回答 默认 最新

  • weixin_33730836 2013-04-04 11:44
    关注

    Are you passing correct arguments to $.post?

    It should be

    $.post("../pChart2.1.3/AllPillarsCoach.php",
                   {name:dataString},
                   function(data){
                     alert(data);
                   }
    );
    

    Check http://api.jquery.com/jQuery.post/ for further reference.

    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大