/    Sign up×
Community /Pin to ProfileBookmark

Delete database row with a link

hi all,

i have a little script for a delete function with a link in php.
now the function works but the page refreshes.
because this will go in to a form.

[B]this is the code[/B].

[U][B]test.php[/B][/U]

[code=php]<?php
include(‘pagina.js’);
include(‘connect_db.php’);

if(isset($_GET[‘delete’]))
{
$query = ‘DELETE FROM RequestLines WHERE RequestLineId = ‘.(int)$_GET[‘delete’];
$result = mysql_query($query);
}

$query = ‘SELECT * FROM RequestLines where RequestId =670 ‘;
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result))
{
echo ‘<div class=”record” id=”record-‘,$row[‘RequestLineId’],'”>
<a href=”?delete=’,$row[‘RequestLineId’],'” class=”delete”>verwijder</a>
<strong>’,$row[‘RequestLineId’],'</strong>
</div>’;

}

?>[/code]
[code=html]<input type=”text” valeu=””>[/code]

this is to check if the page refreshes.

[B][U]pagina.js[/U][/B]

[CODE]$(document).ready(function() {
$(‘a.delete’).click(function(e) {
e.preventDefault();
var parent = $(this).parent();
$.ajax({
type: ‘get’,
url: ‘../test.php’,
data: ‘ajax=1&delete=’ + parent.attr(‘id’).replace(‘record-‘,”),
beforeSend: function() {
parent.animate({‘backgroundColor’:’#fb6c6c’},300);
},
success: function() {
parent.slideUp(300,function() {
parent.remove();
});
}
});
});
});
[/CODE]

can someone help me out here ?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@KorMay 04.2010 — it is hard to say what you sending to the php file via AJAX, as the code is not native Javascript, it is a part of a JavaScript library/template custom code. Which one? JQuery? MooTools?Prototype? Other?
×

Success!

Help @FJSAJ spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...