user1310420
user1310420

Reputation:

Jquery get id from element and include in post

Does anyone know why this isn't working?

$(".v1").click(function(){
$.post("inc.php?action=vote&id="$(this).attr('id')"&vote=1");
});

$(".v2").click(function(){
$.post("inc.php?action=vote&id="$(this).attr('id')"&vote=2");
});

Thanks,

Upvotes: 0

Views: 77

Answers (2)

You need to concatenate the string to your variable content, using + operator, like this:

$.post("inc.php?action=vote&id=" + $(this).attr('id') + "&vote=1");

Upvotes: 1

Atif
Atif

Reputation: 10880

You missed the + between concatenations

$(".v1").click(function(){
$.post("inc.php?action=vote&id=" + $(this).attr('id') + "&vote=1");
});

$(".v2").click(function(){
$.post("inc.php?action=vote&id=" + $(this).attr('id') + "&vote=2");
});

Upvotes: 3

Related Questions