1
JAVASCRIPT
$(document).ready(function(){
$('#parcelas').on('change', function(){
var parcela = this.value;
var entrada = document.getElementsByName("entrada")[0].value;
$("#bodyBoletos").html("");
divida_id = {{$divida->id}};
$.ajax({
url:"/dashboard/admin/negociacao/parcelamento/"+divida_id+"/"+parcela+"/"+entrada,
type: 'get',
dataType: 'json',
success: function(response){
var len = response.length;
for(var i=0; i<len; i++){
var numero = response[i].numero;
var vencimento = response[i].vencimento;
var valor = response[i].valor;
var tr_str = "<tr>" +
"<td>" + numero + "</td>" +
"<td>" + vencimento + "</td>" +
"<td>R$ " +formatMoney(valor) + "</td>" +
"</tr>";
$("#boletos tbody").append(tr_str);
}
},error: function (data) {
var html = '';
if(data.errors)
{
html = '<div class="alert alert-danger">';
for(var count = 0; count < data.errors.length; count++)
{
html += '<p>' + data.errors[count] + '</p>';
}
html += '</div>';
$('#form_result').html(html);
}
}
});
HTML
<span id="form_result"> ...erros aqui... </span>
Hello @André, I saw that you are trying to insert the errors in the html inside the callback error ajax (
,error: function (data){
), I think maybe that’s your problem, usually this callback is executed when something goes wrong with the request (Ex.: Not Found, Internal Server Error, blocked by CORS, no internet, parsererror, ...), if you are returning a json with errors it should be coming to Success.– Icaro Martins
That’s right, I put together Success and adjusted the return in php and it worked.
– André Cabral