?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?
Eric Galluzzo
3,2411 gold badge22 silver badges20 bronze badges
2 Answers 2
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>
answered Jan 4, 2016 at 12:52
Priya Rajaram
3602 silver badges14 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
Jay Blanchard
Why should the OP "try this"? A good answer will always have an explanation of what was done and why it was done that way, not only for the OP but for future visitors to SO.
j.m.l
the link is now on my text but i want it on my img
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>
answered Jan 4, 2016 at 12:47
AnkiiG
3,4861 gold badge19 silver badges28 bronze badges
1 Comment
Adam Azad
You forgot about
echo and the HTML content inside the <script>, go over the code again.default
?phpis not a valid php opening tag. Where is the start tag for<script>?<script>tags, some many things are wrong with above code}in your js code as well. And missed;afterAJAXfunction end.Consoleinside the function