hi i have jquery script when run the page the script working perfectly but when for second its not working unless i refresh the page.
this script is for editing the comments. for first time when edit the comments then submit its update in db and display immediately. when edit the next comment its not working until i refresh the page.. Below is my code
<script type="text/javascript">
$(document).ready(function() {
$(".aaa input:image").click(function(e) {var id=$(this).attr('id');
e.preventDefault();
var cid=$("#"+id+"cid").val();
var comment = $("#"+id+"c").val();
var email=$("#email").val();
var gid=$("#gid").val();
$('.review').click(function(){
var comm=this.id;
var postid=$("#"+comm+"pid").val();
alert(postid);
var value ='comment='+comment+'&cid='+cid+'&email='+email+'&gid='+gid+'&postid='+postid;
$.ajax({
url: "update.jsp",
data: value,
cache: false,
success: function(data) {
$("#"+comm).html(data).slideDown('fast');
}
});
});
});
});
</script>
update.jsp
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="com.util.DB2Connection"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'update.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
System.out.println("comment information in update.jsp..........");;
int cid=Integer.parseInt(request.getParameter("cid"));
System.out.println("comment information cid is..............."+cid);
int gid1=Integer.parseInt(request.getParameter("gid"));
int postid1=Integer.parseInt(request.getParameter("postid"));
System.out.println("post id in update.jsp page is..............."+postid1);
String email=request.getParameter("email");
String comment=request.getParameter("comment");
Connection con=(Connection) new DB2Connection().getDatabaseConnection();
System.out.println("connection test in update.jsp");
Statement st=con.createStatement();
PreparedStatement ps=con.prepareStatement("update user_comment set comment=? where cid=?");
System.out.println("after query in update.jsp");
ps.setString(1,comment);
ps.setInt(2,cid);
int k= ps.executeUpdate();
if(k>0){
String user="",msg="";
Statement st1=con.createStatement();
System.out.println("gid is........"+gid1+"postid is........"+postid1);
ResultSet rs1=st1.executeQuery("select * from user_comment where gid='"+gid1+"' and postid="+postid1);
while(rs1.next())
{
msg=rs1.getString("comment");
user=rs1.getString("email");
int postid=rs1.getInt("postid");
int grid=rs1.getInt("gid");
cid=rs1.getInt("cid");
%>
<div id="review_display">
<input type="hidden" name="cid" value="<%=cid %>" id="cid<%=cid%>"/>
<input type="hidden" name="pid" value="<%=postid %>" id="pid<%=postid%>"/>
<input type="hidden" name="grid" value="<%=grid %>" id="grid<%=postid%>"/>
<input type="hidden" name="email" value='<%=session.getAttribute("email")%>' id="email" />
<p
style="border:0px solid skyblue;width:auto;height:auto;font-weight: bolder;"><%=user%>
: <%=msg%> <img alt="delete" src="images/cancel-icon.png" height=15 width=15 style="cursor:pointer;" önclick="deletecomment('cid<%=cid%>','pid<%=postid%>','grid<%=postid %>','review_display<%=postid1%>');">
</p>
</div> <%}
}
else
{%>
<% String msg="";
String user="";
Statement st1=con.createStatement();
ResultSet rs1=st1.executeQuery("select * from user_comment where gid='"+gid1+"' and postid="+postid1);
while(rs1.next())
{
msg=rs1.getString("comment");
user=rs1.getString("email");
int postid=rs1.getInt("postid");
int grid=rs1.getInt("gid");
cid=rs1.getInt("cid");
%>
<div id="review_display">
<input type="hidden" name="cid" value="<%=cid %>" id="cid<%=cid%>"/>
<input type="hidden" name="pid" value="<%=postid %>" id="pid<%=postid%>"/>
<input type="hidden" name="grid" value="<%=grid %>" id="grid<%=postid%>"/>
<input type="hidden" name="email" value='<%=session.getAttribute("email")%>' id="email" />
<p
style="border:0px solid skyblue;width:auto;height:auto;font-weight: bolder;"><%=user%>
: <%=msg%> <img alt="delete" src="images/cancel-icon.png" height=15 width=15 style="cursor:pointer;" önclick="deletecomment('cid<%=cid%>','pid<%=postid%>','grid<%=postid %>','review_display<%=postid1%>');">
</p>
</div> <%}
}
%>
</body>
</html>
images also not visible unless i refresh the page.
what is the problem in my script please help me
Thanks In Advance