D
D
Denis Vyazemsky2015-09-11 14:55:46
PHP
Denis Vyazemsky, 2015-09-11 14:55:46

Why is JSON AJAX form not submitting?

Why is the form not submitted when fetching data and JSON?
================================================= =====

setInterval(function()  
        {
  SimpleBasket.getData(function(data){ 
  
  var html = [];
  html += '<form id="zk-basketForm" class="basketForm" action="/cart/" method="post">' + '<input type="hidden" name="mode" value="update">' + '<table class="dhunbusket" cellpadding="5" id="cartrestid">';
  

for( var key in data.items) {
    var item = data.items[key]
  var summa = item.SIMPLE_BASKET_QUO * item.SIMPLE_BASKET_PRICE;

     html += '<tr data-product-id="' + key + '">';
        //console.log('  ' + key2, item2)
    html += '<td class="namebusket">' + item.SIMPLE_BASKET_TITLE + '</td>';
    html += '<td class="quooo" data-value="' + item.SIMPLE_BASKET_QUO + '" data-id="' + key + '">' + item.SIMPLE_BASKET_QUO + ' шт.</td>'
    html += '<td class="summ summbusket" data-value="' + item.SIMPLE_BASKET_PRICE + '">' + summa + ' Р</td>'
    html += '<td class="quo" id="zkzk" data-value="' + item.SIMPLE_BASKET_QUO + '" data-id="' + key + '"><div class="cdid"><input class="spinner" type="hidden" name="update_' + key + '" value="' + item.SIMPLE_BASKET_QUO + '" /></div><a class="zk-del didbut" href="javascript:void(0);"></a></td>'
    html += '</tr>';
    //}

}
html += '</form></table>';
  $("#reloadcart").html(html)
  
  });	

}, 1000);

================================================= ===========================================================================================================
_
_ ================================================= =====
The code itself that processes the button click
===================================== =================================
$('.zk-del').click(function(e){
e.preventDefault();
$(this).prev().find('input:first').val(0);
recost();
$('#zk-basketForm').submit();
});

function recost() {
var q = 0;
var p = 0;
$('#zk-basketForm table tr').each(function(){
var quo = $(this).find('td.quo span input:first').val();
var cos = $(this).find('td.price').data('value');
if (quo != undefined) {
q = q + (quo*1);
p = p + cos*quo;
}
});
var res = q + ' товаров | ' + p + ' руб.';
createCookie("__zk_cart_summury__", res, 1);
}

================================================= ==============
Why is the form not being processed? How can I make it so that when a button is clicked in the product line, a form is sent?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sergey, 2015-09-11
@hahenty

Here, the form submit button is recreated at intervals, and the handler flies. To attach a handler to such a button, you will have to write

$('.zk-del').live('click', function(e) {
/** и так далее */
});

or come up with a way to reassign this handler in the same place in the interval.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question