调用$ .post()Jquery没有成功传递参数

时间:2015-02-10 15:30:30

标签: javascript php jquery

    /**
 * Created by quantumveil on 2/10/15.
 */
$(document).ready(function(){


    $('a').on('click',function(){
//$href=$(this).attr('href');
    //console.log($href);
var $convoid=$(this).attr('id');
        console.log($convoid);
    //$('#convoarea').load($href);
        $.get('inbox.php',{convoid:$convoid},function(data){$('#convoarea').html(data);//the callback sets whati t had to

                //now add the on click handler to send button
                $('#send').on('click',function(){
                    var $msgbody=$('#sendbody').val();

                    console.log($msgbody);

///now what i have to do is sent this $msgbody to the inbox.php thru get k

                    $.post('inbox.php',{sendbody:$msgbody,convoid:$convoid},function(data){
                        $('#sendbody').before(data);
                            console.log('here'+$msgbody);
                    });//the callback function will append it to other messages :3
                    return false;
                });


        }//callback ends hre
        );
    return false;

});

    //for send button


});

您好。我试图编写一个社交网站,我希望收件箱具有响应性和动态性。我最近开始学习Jquery。我之前用Google搜索过,没有找到任何帮助,因此它将我带到了这个社区。上面的Javascript / Jquery代码应该在单击SEND按钮时传递一些post参数。另一个文件inbox.php是接收它们并正常工作。现在,这就是我的错误。执行$ .post()的回调函数,所以我假设参数被传递给inbox.php。但是当我尝试使用以下行

在inbox.php中访问它们时
if($msgbody=get_post('sendbody')&&$convoid=get_post('convoid'))

我只收到1的值,而不是消息的实际正文。这里是如何定义函数get_post

function get_post($var1){
    if(isset($_POST[$var1])){$var=$_POST[$var1];
        return filter($var);}
    else return 0;

}

我已尝试直接通过$ _POST [' sendbody']访问它们,但正在生成未定义索引的错误。任何帮助将受到高度赞赏。 (PS在js文件开头的另一个调用.get()是传递参数,所以文件路径没有错误)

编辑:它已修复,但我想要一个解释。我所做的只是在inbox.php中改变了第一行

if($msgbody=get_post('sendbody') 

if(isset($_POST['sendbody'])$msgbody=$_POST['sendbody']

现在我只能想知道它是否与我的get_post()函数定义中的filter()函数有关。任何人

0 个答案:

没有答案