So as you can probably tell, I'm a bit amateur when it comes to jQuery. So if there's any better methods to do what I'm trying to do, please share kindly :) Here's what's happening. Everything works smoothly in the script when you substitute <?php echo $header_id; ?> for a given id that is compatible, say 17. Although $header_id is defined before this script, it must not be really outputting '17'.
I did research before this, not finding anything to help.
So I guess the main question is, does adding a PHP echo really work in this instance, or do I need another method, or is that not even the problem...
$(".vote-button-disabled").click(function (evt) {
$(this).hide().prev("input[disabled]").prop("disabled", false).focus();
var quizid = "";
console.log(quizid);
$.ajax({
url: "scripts/vote-post.php",
type: "POST",
data: {
'quizid' : '<?php echo $header_id; ?>',
'upvote' : '1',
},
success: function() {
console.log('yes!');
},
error: function( xhr, status, errorThrown ) {
alert( "Sorry, there was a problem!" );
console.log( "Error: " + errorThrown );
console.log( "Status: " + status );
console.dir( xhr );
},
complete: function( xhr, status ) {
alert( "The request is complete!" );
}
});
});
Thanks in advanced!
quizidto adata-quizidattribute on the button instead. Then inside click handler :var quizid = $(this).data('quizid')