When I submit the ajax, I need to post three data parameters to process.conversation.php: method, s_state, and c_id. s_state and c_id are found in those two input values. Both variables are correctly being set. I use alert(s_state) and alert(c_id), and they were both as I expected.
Everything works perfectly fine, except my c_id is not getting posted. If I change, in the ajax, c_id: '1', the 1 will be posted as I would expect; however, when I use the variable c_id assigned to 1, it does not get posted (or at least does not get posted with the value I was alerted with…I’m not sure which.) I do, however, get the success toggleClass in all instances.
Note: s_state works exactly as I would expect, as does method. If s_state = '1', it gets posted with that variable. So, I have no idea why c_id is not working.
Any and all ideas are fully welcome.
What might be going wrong?
jQuery/ajax:
$(".__conversation_s").click(function() {
var $thisS = $(this);
var s_state = $thisS.find("input[name='s_state']").val();
var c_id = $thisS.find("input[name='c_id']").val();
jQuery.ajax({
type: 'POST',
url: "./process.conversation.php",
data: {
method: 'star_toggle',
s_state: 's_state',
c_id: 'c_id'
},
cache: True,
success: function() {
$thisS.toggleClass("__starred");
}
});
});
and some html:
<div class='__conversation_s'>
<input type='hidden' name='s_state' value="<?php echo $s_important; ?>">
<input type='hidden' name='c_id' value="<?php echo $c_id; ?>">
</div>
Syntax is incorrect in your data object. You have quotes around the variable names which means they are not variables but strings that contain the same letters as the variable name.
Remove quotes from variables: