0
I’m having trouble using ajax with html.
I have an html file that answers questions from a chat and put the ajax below ajax. It redirects to the question controller and the answer method. The request status is 200, but nothing happens. I debugged and saw that ajax neither access the method, does not pass any of the variables 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 reply button, the information appears on my console.
My project is in MVC and I am using Twig to render the templates. I have a layout.html file, which has the header and another file called formulario.html, which would be between {% block formulario %} and {% endblock %}. My ajax is along with the.html form.
Yes, the messages appear.
– milho
The problem may be in the url. Try using the absolute url. Example: htttp://www.seusite.com.br/questions/answer
– Roberto Giffone