0

I want to post the PHP variables $uid and $submissionid to the file fblike.php. Is the Ajax below formatted correctly to do this?

<?php


ob_start();
session_start();

$uid = $_SESSION['loginid'];

$submissionid = mysql_real_escape_string($_GET['submissionid']);
$_SESSION['submissionid'] = $submissionid;


?>


<head>


<script type='text/javascript' src='jquery.pack.js'></script>
<script type='text/javascript'>
$(function(){
    $("a.connect_widget_like_button").live(function(){

        $.ajax({
            type: "POST",
            data: "action=vote_up&uid="+$(this).attr("uid")"&submissionid="+$(this).attr("submissionid"),
            url: "fblike.php",

        });
    });


}); 
</script>

</head>

2 Answers 2

2

You dont really want to use expando attributes if you dont have to, especially since thise are links... i would jsut do:

<a href="fblike.php?ction=vote_up&uid=1&&submissionid=1">Like</a>

then you can do a simple:

$("a.connect_widget_like_button").live('click', function(e){
   e.preventDefault();
   $.post($(this).attr('href'));
});

Now on the php side you need to be aware of where the values will be. If you pass the values as i have done in my example they will be in $_GET (even if its a POST request). If you pass them like you did in your original post then they will be in $_POST.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks... I didn't use your exact solution but putting the URL in the href with the Facebook Like button led me down the right path.
0

You need to send the data as an array/object. Something like this should do the trick.

$(function(){
    $("a.connect_widget_like_button").live(function(){

        $.ajax({
            type: "POST",
            data: {
                action: "vote_up",
                uid: $(this).attr('uid'),
                submissionid: $(this).attr('submissionid')
            },
            url: "fblike.php"
        });
    });
}); 

1 Comment

While passing data as a hash is much easier to read (and i also prefer it) using a query string will work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.