Pregunta

Can someone please with more experience on it help me with this?

This is not working and I don't know why.

I got it from the internet but the example was with php, so, not sure.

Update.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page language="java"%>
<%@page import="java.lang.*" import="org.postgresql.*" import="java.sql.*"%>

<!DOCTYPE html>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
        try {

            Class.forName("org.postgresql.Driver");
            String url = "jdbc:postgresql://localhost:5432/postgres";
            Connection connection = DriverManager.getConnection(url,
                    "postgres", "admin");

            String strquery = "UPDATE projects SET project = '"
                    + request.getParameter("id") + "'";

            Statement st = connection.createStatement();

            //System.out.println("Connecting to database...");
            ResultSet rs = st.executeQuery(strquery);

            System.out.println(strquery);

            rs.close();
            st.close();
        } catch (Exception e) {
            System.out.println(e);
        }
    %>
</body>
</html>

ContenteditableTest.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

<!DOCTYPE html>

<html>
<head>
<script type="text/javascript" src="js/jquery-1.9.1.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Contenteditable test</title>

<script>
    $('.id').keyup(function() {
        delay(function() {
            var text = $('.id').text();
            $.ajax({
                type : "post",
                url : "update.jsp",
                data : "text=" + text,
                success : function(data) {
                    console.log('success bro!');
                }
            });
        }, 500);
    });

    var delay = (function() {
        var timer = 0;
        return function(callback, ms) {
            clearTimeout(timer);
            timer = setTimeout(callback, ms);
        };
    })();
</script>    
</head>    
<body>
    <table>
        <tr>
            <td contenteditable="true" class="id">1</td>
        </tr>
    </table>
</body>    
</html>
¿Fue útil?

Solución

Hi first of in your update.jsp you have mention request.getParameter('id') but in ContenteditableTest.jsp in ajax call you have mention data : "text=" + text, so either change "text=" to "id=" in ContenteditableTest.jsp or request.getParameter('id') to request.getParameter('text') in update.jsp.

And for contenteditable attribute you can follow this Post https://plus.google.com/114254873085584811912/posts/LqpzvvzoMYc

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top