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:

$( document ).ready(function() {
    $.post( "_corps_medecin_changedate.php", { name: 'test', id: '1' } );

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

$date_debut = $_POST['name'];

And i got msg:

array (size=0)
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问答提供 功能建议



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

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

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


  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

        $( document ).ready(function() {
                $("#consultations_jour").load("_corps_medecin_changedate.php", { name: 'test', id: '1' });
    打赏 评论
  • dtsc14683 2013-10-17 10:54

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

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

    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 can use callback... to check the datas that you have posted

      $.post( "_corps_medecin_changedate.php", { name: 'test', id: '1' },function(data){

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

    打赏 评论

相关推荐 更多相似问题