I'm having trouble using ajax with html.
I have an html file that answers questions from a chat and I put the ajax below ajax. It redirects to the controller questions and the answer method. The request status is 200, but nothing happens. I have debugged and seen that ajax does not access the method, it does not pass any of the variables that I need.
$(document).ready(function(){
$(".form-response").on('click',function(e){
e.preventDefault();
var seller_id = $(this).attr("seller_id");
var dataValue = $(this).attr("data-value");
var resposta = $("#resposta-pergunta-" + dataValue).val();
console.log(dataValue);
console.log(resposta);
console.log(seller_id);
$.ajax({
method: 'POST',
url : '../perguntas/responder',
data: {
id: dataValue,
resposta: resposta,
seller_id: seller_id
}}).done(function(data){
console.log($("#card-" + dataValue).hide());
alert("Respondido com Sucesso! - Ajax");
}).fail(function(){
alert('Problema para RESPONDER');
});
return false; });
When I click the answer button, the information appears in my console.
My project is in MVC and I'm using twig to render the templates. I have a layout.html file, which has the header and another file called form.html, which would be between the {% block form%} and {% endblock%}. My ajax is along with the form.html