I can't find topic about Ajax here, so i'm sorry if already have topic for ajax .
I have a question : I have a delete.jsp , that have a table with link to call Servlet to Delete a row on each row , and i use ajax to handle it . It's work, but after delete , the row that deleted not disappear until i click F5 to refresh page .
I'm newbie with ajax, please hint me ! thanks !
This is my code :
delete.jsp
<script type="text/javascript">
function getXMLObject() //XML OBJECT
{
var xmlHttp = false;
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP") // For Old Microsoft Browsers
}
catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP") // For Microsoft IE 6.0+
}
catch (e2) {
xmlHttp = false // No Browser accepts the XMLHTTP Object then false
}
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
xmlHttp = new XMLHttpRequest(); //For Mozilla, Opera Browsers
}
return xmlHttp; // Mandatory Statement returning the ajax object created
}

var xmlhttp = new getXMLObject(); //xmlhttp holds the ajax object

function ajaxFunction(t) {
//Used to prevent caching during ajax call
if(xmlhttp) {
xmlhttp.open("GET","../Servlet?id="+t+"" ,true); //
xmlhttp.onreadystatechange = handleServerResponse;
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send(null);
}
}

function handleServerResponse() {
if (xmlhttp.readyState == 4) {
if(xmlhttp.status == 200) {
//document.myForm.demo.value=xmlhttp.responseBody; //Update the HTML Form element
//window.open("delete.jsp", "_self");
}
else {
alert("Error during AJAX call. Please try again");
}
}
}
</script>

<% String id = "", name="";
float salary=0;%>
<h1>Hello Aptech Role</h1>
<%

Connection connection = null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection = DriverManager.getConnection("jdbc:odbc:DemoBaiThi" , "sa", "");

Statement statement = connection.createStatement();


ResultSet resultset =
statement.executeQuery("select * from employee");

while(resultset.next())
{
id = resultset.getString(1);
name = resultset.getString(2);
salary = resultset.getFloat(3);
%>
<form name="myForm" >
<TABLE BORDER="1" id="demo">
<TR>
<TH>ID</TH>
<TH>Name</TH>
<TH>Salary</TH>
<TH>Delete</TH>
</TR>
<TR>
<TD> <%= id %> </TD>

<TD> <%= name %> </TD>
<TD> <%= salary %> </TD>
<TD>
<input type="button" onClick="javascript:ajaxFunction(<%=id%>);" value="Delete"/>
</TD>
</TR>
</TABLE>
</FORM>
<%
}
%>



and this is my Servlet to Delete a Row

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String action = request.getParameter("action");
try
{
connect();
String id = request.getParameter("id");
String str = "Delete from employee where employeeID = "+id+"";
stm.executeQuery(str);
response.sendRedirect("delete.jsp");
} catch (SQLException ex) {
ex.printStackTrace();
} finally
{
out.close();
}

}