除非我刷新页面,否则脚本不会运行 [英] script is not running unless i refresh the page

查看:72
本文介绍了除非我刷新页面,否则脚本不会运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我有jquery脚本,当运行页面脚本工作完美但第二次它不工作,除非我刷新页面。



这个脚本用于编辑评论。第一次编辑注释然后在db中提交更新并立即显示。当编辑下一个评论时它才工作,直到我刷新页面..下面是我的代码



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",
     //type: "post",
     data: value,
     cache: false,
     success: function(data) {
     $("#"+comm).html(data).slideDown('fast');

     }
     });
});
});
});
</script>





update.jsp





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

推荐答案

文档)。ready( function (){
(document).ready(function() {


.aaa input:image )。click( function (e){ var id =
(".aaa input:image").click(function(e) {var id=


this )。attr(' id');
e.preventDefault();
var cid =
(this).attr('id'); e.preventDefault(); var cid=


这篇关于除非我刷新页面,否则脚本不会运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆