Author Topic: Frustrating jquery bug, be my savior?  (Read 523 times)

0 Members and 1 Guest are viewing this topic.

Offline PsychoRebellious

  • Peasant
  • *
  • Posts: 130
  • Cookies: -6
    • View Profile
    • My Rantings
Frustrating jquery bug, be my savior?
« on: February 10, 2015, 12:33:59 pm »
inbox.js
Code: [Select]
/**
 * 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;

});


Hi. I'm trying to code a social networking site and I want the inbox to be responsive and dynamic. I've recently started learning Jquery for the purpose being. I've googled this before and found no help and so it brings me here on this community. The above Javascript/Jquery code is supposed to pass some post parameters when the SEND button is clicked. Another file, inbox.php, is to receive those and work appropriately. Now here's what bugs me. The callback function to $.post() is executed, so I'm assuming the parameters are being passed to inbox.php. But when I try accessing them in inbox.php using following line

if($msgbody=get_post('sendbody')&&$convoid=get_post('convoid'))

I only receive a value of 1 and not the message's actual body. Here's how the function get_post is defined

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

}

I've tried accessing them directly through $_POST['sendbody'] but an error of undefined index is being generated. Any help will be highly appreciated. (PS the other call to .get() in the beginning of this js file is passing the parameters so there's nothing wrong with file paths)
« Last Edit: February 10, 2015, 01:16:29 pm by PsychoRebellious »

Offline KryDos

  • Serf
  • *
  • Posts: 42
  • Cookies: 8
  • Software Engineer, Emacs uesr
    • View Profile
Re: Frustrating jquery bug, be my savior?
« Reply #1 on: February 28, 2015, 11:44:05 pm »
Hey,
I know it's old post... but I will try...

what does your filter function (in the get_post function)?
try var_dump/print_f for your $_POST array when your index.php page receives ajax request.
also, are you sure that your javascript sends correct data? did you try to check what data your script sends? You can use your browser's developer tools to check this.