spires Posted November 22, 2010 Share Posted November 22, 2010 Hi I have a list that is being pulled out of the database, and want to use AJAX to be able to delete any one of the rows. I have sucessfully achieved this, however, after deleting the row from the database, it does not show on the page untill after a page refresh? This defeats the point of wanting to use AJAX if I have to refresh the page. Any help with this will be much appreciated. HTML <?PHP foreach($list as $lists){ if($flag==1){ $class='class="even"'; }else{ $class='class="odd"'; } $ID = $lists->id; $country_id = $lists->country_id; $county_id = $lists->county_id; $town = ucwords($lists->town); echo ' <div '.$class.'> <div class="left1c">'.$town.'</div> <div class="left3"><a href="edit_area.php?id='.$ID.'"><img src="images/wrapper/edit2.png" width="18" height="16" alt="edit" /></a> <a href="#" onClick="delArea('.$ID.');return false;"><img src="images/wrapper/delete.png" width="15" height="16" alt="delete" /></a></div> <div class="clear"></div> </div>'; } ?> JAVASCRIPT function delArea(ID){ AJAXAdmin("lib/ajax_php/delete_area.php?id="+ID+""); } DELETE <?PHP require_once("../../../includes/initialize.php"); $ID = $_GET['id']; $setID = new Area_town(); $newID = $setID->id = $ID; if($setID && $setID->delete()){ $msg = "Success: The entry has been deleted."; }else{ $msg = "Sorry: There was an error please try again."; } echo $msg; ?> AJAX var xmlhttp = false; var internal_key; var rsval1; function AJAXAdmin( URL) { try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }catch(E){ xmlhttp = false; } } if ( !xmlhttp && typeof XMLHttpRequest!='undefined' ) { xmlhttp = new XMLHttpRequest(); } var now = new Date(); xmlhttp.open("GET", URL, true); xmlhttp.onreadystatechange = AjaxAdminDone; xmlhttp.send(null); } function AjaxAdminDone(){ try{ if(xmlhttp.readyState != 4) return; }catch(E){ return } try{ var strResp = xmlhttp.responseText.toString() ; document.getElementById('error').innerHTML = strResp; xmlhttp = null ; } catch(E){ alert(E.message + ' -- ' + strResp ); } } Thanks Quote Link to comment https://forums.phpfreaks.com/topic/219470-need-help-removing-the-row-after-it-has-been-deleted/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.