3
I’m trying to return in Jquery comment data and end a form
to add 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 fixed 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; }); });
Now the following has occurred. I was able to bring the fomulário and the comments. I am trying to send the form data doing exactly as I did with the previous script, but as the form is already loaded, it will not.
put a variable to receive this id before executing the function.
– Rod
Thinking about it...only enters the function by clicking, I can not do this.
– Rod
I solved it, put the dynamic id and clicked the class.
– Rod