script document ready function button_ajax click function var name nam

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<script>
$(document).ready(function() {
$('#button_ajax').click(function() {
var name = $('#name').val();
var phone = $('#phone').val();
var id_product = 1;
var domain = document.location.host;
var obj = {
"name": name, "phone": phone, "id_product": id_product, "domain": domain
};
var param = JSON.stringify(obj);
$.ajax({
type: "POST",
url: 'http://adminversiya.install/admin/save_data',
data: param,
success: function(res) {
if (res === 'hello') {
var html_modal = '<div id="my_modal" class="modal"><div class="modal_content"><div class="close_modal">×</div><div class="content_text"><div class="title_modal_form">'+name+', поздравляем!</div><div class="lead title_modal_form2">Ваш заказ успешно принят.</div><div>Наш менеджер свяжется с Вами в течении 15 минут</div></div></div></div>';
$('body').append(html_modal);
$('#my_modal').css('display', 'block');
$('.close_modal').on('click', function() {
$('#my_modal').css('display', 'none');
});
$(document).mouseup(function (event) {
var container = $('#my_modal');
if (container.has(event.target).length === 0) {
$('#my_modal').css('display', 'none');
}
$('#name').val('');
$('#phone').val('');
});
}
}
});
});
});
</script>