У меня есть цикл while для создания таблицы данных и щелчка мышью. Я хочу вызвать функцию, но когда я вызываю функцию, она не получает информацию от передаваемого щелчка мышью.
HTML:
echo "<td width='25%' align='center'><a href='javascript:void(0)' id='{$row['id']}' class='{$row['status']}' onclick='hello()'> {$row['status']} </a></td>";
JS:
//onclick function
function hello()
{
// Get the ID of the button that was clicked on
var id_of_status_to_update = $(this).attr("id");
var status_to_be_updated = $(this).attr("class");
var varData = 'id=' + id_of_status_to_update + '&UserStatus=' +
status_to_be_updated;
console.log(varData);
// Make an AJAX request
$.ajax({
url: "php/processor.php", //This is the page where you will handle your SQL insert
type: "POST",
data: varData, //The data your sending to processor.php
async: false,
success: function(){
// location.reload();
alert("Hello Function");
},
error: function(){
alert("There was a problem, please try again or contact the admin for assistance.");
}
});
};
но когда я проверяю журнал консоли, я вижу, что id и userstatus не определены, вместо того, что должно быть переданными атрибутами id и class. Любая помощь? Я знаю, что функция вызывается правильно, потому что я получаю предупреждение об успехе.