Reputation: 211
Ajax :
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#button").click(function(){
var insPer =$("#insPer").val();
var insPos =$("#insPos").val();
$.ajax({
url:'../validate/inspire.php',
method:'POST',
data:{
u_id:insPer,
p_id:insPos
},
success:function(data){
//alert(data);
}
});
});
});
</script>
This is my input and button
<span class="views" data-toggle="tooltip" title="Inspired">
<input type="hidden" id="insPer<?php echo $p_id; ?>" name="insPer">
<input type="hidden" id="insPos<?php echo $p_id; ?>" name="insPos">
<a href="#" role="button" id="button<?php echo $p_id; ?>" type="submit">
<img src="../images/lightbulb-regular.svg" class="like-btn-svg">
</a>
</span>
Here input id comes from looping each post. The id values changing like example :
loop1 {insPer1,insPos1,button1},
loop2 {insPer2,insPos2,button2},
I'm passing these IDs in ajax but that id values are not changing.
Upvotes: 0
Views: 62
Reputation: 979
try setting the hidden elements' value using the value
attribute...
<span class="views" data-toggle="tooltip" title="Inspired">
<input type="hidden" id="insPer" name="insPer" value="<?php echo $p_id; ?>" />
<input type="hidden" id="insPos" name="insPos" value="<?php echo $p_id; ?>" /> <-- assuming $p_id should be the value of this input element -->
<a href="#" role="button" id="button" type="submit">
<img src="../images/lightbulb-regular.svg" class="like-btn-svg">
</a>
</span>
Upvotes: 1