2
After a lot of trying I arrived at this result of JQUERY AJAX, but I still could not use the JSON data, they do not work, how should I do ? give a Help ! thank you
The JSON response ta at the end
jQuery(document).ready(function() {
jQuery('#add-to-cart-head').submit(function() {
var $this = jQuery(this),
dados = $this.serialize();
jQuery.ajax({
type: "POST",
datatype: 'json',
url: $this.attr('action'),
data: dados,
complete: function (mensagem) {
$.getJSON($this.attr('action'), function(dados) {
for(var i=0; i<dados.length; i++) {
$('#tbody-head-cart').append
('<tr class="cart-header-thumb">' +
'<td class="cart-head-img">' +
'<img src="' + dados[i].image + '" alt="" title="">' +
'<div class="remove-add-cart-header">' +
'</div>' +
'</td>' +
'<td class="cart-head-description">' +
'<strong>' + dados[i].name + '</strong>' +
'<div>' + dados[i].tamanhos + '</div>' + '<div>' + cores + '</div>' +
'</td>' +
' <td class="cart-head-price">' +
' <div class="strike"><strike>' + dados[i].price + '</strike></div>' +
' <span class="sale">' + dados[i].saleprice + '</span>' +
'<div class="cart-header-thmub-change">' +
' <input class="form-control" name="' + dados[i].cartkey + '" value="1" style="width: 50%;" type="text">' +
'<a class="alter_qty" href="#" onclick="$(this).parents("form:first").submit(); return false;">' +
'Alterar' +
'</a></div><a class="alter_qty" href="#" onclick="$(this).parents("form:first").submit(); return false;">' +
'</a>' +
'</td>' +
' </tr>');
}
});
},
error: function(){
alert("message");
}
});
return false;
});
});
{"error":true,"message":"","total_items":1,"total":99,"cart_items":{"2099159d6749e3c101925ffc4bc24bbb":{"name":"Vestido","price":"99.00","saleprice":"89.00", "options":{"tamanhos":"p"}}}
That’s what I was looking for, thank you Sergio
– Gladson Gilberto Marinho Gonal