View Single Post
Old 01-16-2013, 07:03 PM   PM User | #1
LJackson
Senior Coder

 
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
LJackson is on a distinguished road
Exclamation Ajax Help Please, trying to call a php script via an onclick event?

is it possible to use an onclick event command on a text link to call a php script which deletes a specific row from a mysql db table?

here is what i have so far.

my text link code
Code:
<a class="deleteRow" onclick="
  $.ajax({
    type: 'post',
    url: "http://www.{WEBSITEDOMAIN}.co.uk/delete.php",
    data: {joodb field|id},
  });
;" href="#">Delete</a>
and my php file
PHP Code:
<?php
if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
  
$id = (int) $_POST['id'];
  
// make sql query to remove element with given id
  
echo '<script type="text/javascript">window.alert("$id")</script>';
}
?>
at the moment the php file just displays an alert box, just to confirm the script is being called and the correct id value is being passed.

unfortunately when i press on the text link nothing happens, or so it appears! if i open firebug and then click on the console tab it gives the following error

Code:
SyntaxError: syntax error
https://s-static.ak.facebook.com/connect/xd_arbiter.php?version=18
Line 13
which is odd as there is no facebook on this page??? and the error only comes up when i click on the text link.

can anyone help me with this please?
many thanks

Luke
__________________
Kernow Connect: Online Shopping, Price Comparison, Maximum Savings On Top UK Stores
Follow Us On: Twitter | Facebook
LJackson is offline   Reply With Quote