user1481850
user1481850

Reputation: 248

Jquery post multiple vars to php

I want to post multiple vars from jquery to php

<script>
//vote script
function vote(type){
$.post('vote.php', '{user_id: <?php echo $fb_userid;?>, page_name: <?php echo $get_image;?>, type: type}', function(data){
    $('#voteNumber').html(data);
    });
    }//end function
</script>

The above code is not working what is my problem ?

here is my php

if(isset($_POST['user_id']) && isset($_POST['page_name']) && isset($_POST['type'])){
        echo "done";
    }

Upvotes: 0

Views: 160

Answers (2)

Bill Effin Murray
Bill Effin Murray

Reputation: 436

<script>
//vote script
function vote(type){
    $.post('vote.php', { user_id : '<?php echo $fb_userid;?>', page_name : '<?php echo $get_image;?>', type : type}, function(data){
        $('#voteNumber').html(data);
    });
}//end function
</script>

In your brackets, you had the entire thing surrounded by quotes. Only the value must be in quotes.

{ key : 'val', key2 : 'val2' }

Upvotes: 3

Ibu
Ibu

Reputation: 43810

The quotes are not needed, this is javascript

you are passing an object directly as a parameter

<script>
//vote script
function vote(type){
    $.post('vote.php', {user_id: <?php echo $fb_userid;?>, page_name: '<?php echo $get_image;?>', type: type}, function(data){
        $('#voteNumber').html(data);
    });
}//end function
</script>

Upvotes: 0

Related Questions