I am trying to return comments data in JQuery and to end a form
to enter more comments.
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"type="text/javascript"></script>
<script type="text/javascript">
$(function() {
$("#exibir-comentario").click(function(){
var valor = $("#exibir-comentario").attr('rel');
var dados = $("#resposta-form"+valor+"")
$.ajax({
type: "POST",
url: "comentarios.asp?id_questao="+valor+"",
success: function(resposta) {
dados.html(resposta);
},
beforeSend: function(){
dados.html('Buscando...');
},
error: function(data) {
dados.html('Erro ao buscar!');
}
});
return false;
});
});
</script>
</head>
<body>
<%questao=1%>
<a id="exibir-comentario" rel="<%=questao%>" href="#">Exibir fomulário</a>
<div id="resposta-form<%=questao%>"></div>
<%questao=2%>
<a id="exibir-comentario" rel="<%=questao%>" href="#">Exibir fomulário</a>
<div id="resposta-form<%=questao%>"></div>
</body>
</html>
But the second link does not return.
I solved by putting the dynamic id and making the class receive the click.
//carrega comentarios $(function() { $("a.link").click(function(){ var valor = $(this).attr('id'); var dados = $("#resposta-form"+valor+"") $.ajax({ type: "POST", url: "comentarios.asp?id_questao="+valor+"", success: function(resposta) { dados.html(resposta); }, beforeSend: function(){ dados.html('Buscando...'); }, error: function(data) { dados.html('Erro ao buscar!'); } }); return false; }); });
The following has now occurred. I was able to bring the form and the comments. I'm trying to send the data from the form doing exactly as I did with the previous script, but as the form is already loaded, it will not.