uso de ajax en la eliminación de una fila

I have a webpage that has several rows of data coming in mysql database. Im new to ajax i just try it right now, because of the reason that i want to delete row without refreshing the web page. I just want to ask if my code in ajax is correct or did I use it right. here is my code.

this is the generating of rows

            $d = mysql_query("select * from hrd_ot");   

                print"<tr id='row".$e."'>
                <td><a href='#' onclick=\"return samplexx(".$x['id'].",row".$e.")\">OK</a></td>

and here is my ajax script | source

function samplexx(id,row)
    var xmlhttp;
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

and here is my sample.php


mysql_query("delete from hrd_ot where id='{$_GET['id']}'");

also it is possible the row that i've choose to delete will delete without using this line of code"none";

preguntado el 12 de febrero de 14 a las 08:02

Is your code working? -

yes, at first when i dont put this code"none"; the deleted row is remain but when I refresh i it disappear -

Please show how you are calling the samplexx() función -

1 Respuestas

Tengo algunas sugerencias.

Instead of using the "GET" method you should use the DELETE method if you are following REST.

It wil be good if you can check for the status of the xmlHttpREquest.

if (xmlhttp.readyState==4 && xmlhttp.status==200)
//hide row

row in your samplexx function is not a jquery reference to the selected row. So you should either use




The below line just hides the row from the table. So that you dont have to refresh the page and fetch the new list of rows. Do this only if the server returned with 200 status.


Respondido 12 Feb 14, 08:02

Sir I think I must read first what is the use of .readyState==4 and .status==200 - Roberto Juan Concepción

Sir can you explain what is 200 status? - Roberto Juan Concepción

Its the HTTP status code. Every response will have a status code. eg: 200 success 404 not found refer this link - Konza

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.