dongxing2030
2013-10-17 10:51
浏览 113

jquery ajax表单已发送,但var_dump($ _ POST)为空

everyone, i got a very simple problem, but i am really confused... for un hour

in a php page, i have the code:

<script>
$( document ).ready(function() {
  $("#date_avant").click(function(){
    $.post( "_corps_medecin_changedate.php", { name: 'test', id: '1' } );
    $("#consultations_jour").load("_corps_medecin_changedate.php");
  });
});
</script>

And in the page _corps_medecin_changedate.php, just at the beginning, i have the code:

<?php
var_dump($_POST);
$date_debut = $_POST['name'];
?>

And i got msg:

array (size=0)
  empty
Notice: Undefined index: name

I checked the firebug, the parameters are correct in the post list, so i thinked it is sended correctly, but just canot receive in the action page.

Server info :   Apache/2.2.11 (Win32) PHP/5.4.4

And in local envirment.

Can anyone help me?

图片转代码服务由CSDN问答提供 功能建议

每个人,我都遇到了一个非常简单的问题,但我真的很困惑......一小时

在php页面中,我有代码:

 &lt; script&gt; 
 $(document).ready(function(){
  $(“#date_avant”)。click(function(){
 $ .post(“_corps_medecin_changedate.php”,{name:'test',id:'1'}); 
 $(“#consultation_jour”)  .load(“_ corps_medecin_changedate.php”); 
}); 
}); 
&lt; / script&gt; 
   
 
 

在页面_corps_medecin_changedate.php ,就在开头,我有代码:

 &lt;?php 
var_dump($ _ POST); 
 $ date_debut = $ _POST ['name']; \  n?&gt; 
   
 
 

我得到了msg:

  array(size = 0)
 empty \  nNotice:未定义索引:名称
   
 
 

我检查了firebug,参数在帖子列表中是正确的,所以我认为它被正确发送,但只是canot接收 操作页面。

 服务器信息:Apache / 2.2.11(Win32)PHP / 5.4.4 
    
 
 

在当地的环境中。

任何人都可以帮助我吗?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • drkug66408 2013-10-17 10:55
    已采纳

    Your returned data from your $.post call is not automatically made available to your .load() call. They are two separate functions which means your call to load essentially send no POST data to the PHP script.

    You can pass the post parameters as part of your call to load

    <script>
        $( document ).ready(function() {
            $("#date_avant").click(function(){
                $("#consultations_jour").load("_corps_medecin_changedate.php", { name: 'test', id: '1' });
            });
        });
    </script>
    
    已采纳该答案
    打赏 评论
  • dtsc14683 2013-10-17 10:54

    You have to handle result of post request in callback function, like this:

    <script>
    $( document ).ready(function() {
       $("#date_avant").click(function(){
        $.post( "_corps_medecin_changedate.php", { name: 'test', id: '1' }, 
             function(result) { $("#consultations_jour").html(result);} );
      });
    });
    </script>
    

    In your code you make 2 different requests (first is in .post function, and second is in .load).

    打赏 评论
  • dsoxcj7276 2013-10-17 10:56

    that is because your are calling the _corps_medecin_changedate.php again right (.load()), after the post is made with no posted datas.. and you are not using callbacks..

     $("#consultations_jour").load("_corps_medecin_changedate.php"); //here
    

    Since post is async... the .load() function (which isn't inside a post's callback) is called right after you call post and does not waits for it

    i have no idea why are you loading the same php page again after post it made which i don't think is needed...but as an example ...you can use callback... to check the datas that you have posted

      $.post( "_corps_medecin_changedate.php", { name: 'test', id: '1' },function(data){
         alert('done');
      });
    
     //$("#consultations_jour").load("_corps_medecin_changedate.php");
    

    try this and you should get the posted values in your PHP page.

    打赏 评论

相关推荐 更多相似问题