Reputation: 27
?php foreach($participants as $participant) {
echo "<tr>";
echo "<td>" . $participant['Vorname'] . "</td>";
echo "<td>" . $participant['Auto'] . "<img id=$participant[name_id] onclick='deleteDriver()' class='delete' src='img/tonne.gif' align='right' data-url='backend/queries.php?decision=deleteDriver&id=".$participant['name_id']."'/></td>";
echo "</tr>";
}
?>
function deleteDriver()
{
var dataString = "decision=deleteDriver";
$.ajax({
type: 'POST',
url: 'queries.php',
data: dataString
}
})
}
</script>
When I push the button the function is not called. Why?
Upvotes: 1
Views: 65
Reputation: 3488
You have missed <script>
open tag before function deleteDriver()
. Please add and retry. Try as below :
<?php
foreach($participants as $participant) {
echo "<tr>";
echo "<td>" . $participant['Vorname'] . "</td>";
echo "<td>" . $participant['Auto'] . "<img id='".$participant['name_id']."' onclick='deleteDriver()' class='delete' src='img/tonne.gif' align='right' data-url='backend/queries.php?decision=deleteDriver&id=".$participant['name_id']."'/></td>";
echo "</tr>";
}
?>
<script>
function deleteDriver()
{
var dataString = "decision=deleteDriver";
$.ajax({
type: 'POST',
url: 'queries.php',
data: dataString
}
});
}
</script>
Upvotes: 1
Reputation: 360
try with this code.
<?php
foreach($participants as $participant) {
echo "<tr>";
echo "<td>" . $participant['Vorname'] . "</td>";
echo "<td><a onclick='deleteDriver()'>" . $participant['Auto'] . "<img id=$participant[name_id] class='delete' src='img/tonne.gif' align='right' data-url='backend/queries.php?decision=deleteDriver&id=".$participant['name_id']."'/></a></td>";
echo "</tr>";
}
?>
<script>
function deleteDriver()
{
var dataString = "decision=deleteDriver";
$.ajax({
type: 'POST',
url: 'queries.php',
data: dataString
})
}
</script>
Upvotes: 1