$(function () { $(document).on('click', 'form.l_form .l_form_submit', function (e) { e.preventDefault(); $('.l_form .form-group').removeClass('has-error'); $('.l_form').find('.l_form_error_message').remove(); var action = $(this).data('action'); var form = $('#l_form_' + action); var product_id = $('.product_id').data('productId'); var product_id_input = form.find('input[name=product_id]'); if (product_id_input.length === 0) form.append(''); var data = form.serialize(); $.ajax({ url: '/ajax/l_form.php', data: {data: data, action: action}, dataType: "json", type: "POST", success: function (response) { console.info(response); if (response.error === 'Y') { $('#l_form_' + action + ' .' + response.loc).parent().addClass('has-error'); $('.l_form_error_message').html(response.error_text); $('#modal_' + action + ' #l_form_alert_error').fadeIn(); } $('.l_form input').on('focus', function () { $('.l_form .form-group').removeClass('has-error'); $('#modal_' + action + ' #l_form_alert_error').hide(); }); if (response.success === 'Y') { $('#modal_' + action).modal('hide'); $('#modal_success div.modal_message').html(response.message); $('#modal_success').modal('show'); if (action === 'request_feedback') window.actionSeo.actionRequestFeedback(); if (action === 'ask_question') window.actionSeo.actionAskQuestion(); if (action === 'fast_buy') window.actionSeo.actionFastBuy(); } } }); }); }); $('#optsubmit').on('click',function(){ var optname = $('input[name=optname]').val(); var optmail = $('input[name=optmail]').val(); var optphone = $('input[name=optphone]').val(); $.ajax({ type: 'POST', url: '/ajax/l_form.php', dataType: 'json', data: { 'action': 'zajavka_opt', 'optname':optname, 'optmail':optmail, 'optphone':optphone, }, success: function(data) { if (data.result == 'ok') { $('div#optform').hide('slow'); $('div#optOk').show('slow'); } else { $('#opterror').slideUp('normal',function(){$(this).html(data.error)}).slideDown(); } }, error: function(data) { $('#opterror').slideUp('normal',function(){$(this).html('Не могу подключиться')}).slideDown(); } }); })