I have the following code:
$(document).ready(function(){
var btn = $('a.btn-primary');
var closeDate = $('td.closeDate');
var applyBtn = $('<input type="button" value=" Apply " class="toggleButton" \>');
//Rmove a link
btn.remove();
//Add button
applyBtn.insertAfter(closeDate);
$('.toggleButton').click(function(){
var obj = $(this).closest('tr');
var data = {
vacancyID: obj.find('td.vacancyID').text(),
closeDate: obj.find('td.closeDate').text(),
roleLongTitle: obj.find('td.roleLongTitle').text(),
roleRequirements: obj.find('td.roleRequirements').text(),
roleResponsibilities: obj.find('td.roleResponsibilities').text(),
roleQualifications: obj.find('td.roleQualifications').text(),
}
//Post the data to the page
$.ajax({
type: 'POST',
url: 'vacancy.php',
data: data,
success: function(data){
alert(data);
}
});
//$.post("vacancy.php", data, function(){
//alert(data);
//});
console.log(data.vacancyID);
})
});
In the console the data display correct, but alert shows something completely. The page I am posting all also don't see the post. See image below:
I was expecting to only see the data that relates to the button I clicked and not both vacancies. Can anyone please help and tell we where I am going wrong.