|
javascript / set_to_modal_other | ☑ | ||
---|---|---|---|---|
0
PQT
22.05.18
✎
04:51
|
ПОЧЕМУ РАБОТАЕТ ТАК:
function set_to_modal_other(what){ $("#target").submit(function() { $.ajax({ type: "POST", url: what, data: $(this).serialize(), cache: false, success: function(html){ $('#modal_other').html(html); } }).done(function() { $("#modal_other").trigger("reset"); set_to_modal_other(what); }); return false; }); return true; } НО НЕ РАБОТАЕТ ТАК: function ajax_modal_other(what){ return $.ajax({ type: "POST", url: what, data: $(this).serialize(), cache: false, success: function(html){ $('#modal_other').html(html); } }); } function set_to_modal_other(what){ $("#target").submit(function() { ajax_modal_other(what).done(function() { $("#modal_other").trigger("reset"); set_to_modal_other(what); }); return false; }); return true; } |
|||
1
PQT
22.05.18
✎
04:54
|
я 1Сник, а в JS дилетант, но не могу понять почему лыжи не едут
|
|||
2
Asmody
22.05.18
✎
07:04
|
(1) Потому что this в javascript - это очень "волшебная" штука.
https://tproger.ru/translations/javascript-this-keyword/ Тебе во втором случае надо $(this).serialise() вынести из внутренней функции |
|||
3
PQT
22.05.18
✎
08:39
|
ok, понял, псб!
|
|||
4
PQT
22.05.18
✎
08:57
|
помогло, длиннющая портянка сокрадилась до:
function modalOnIndex(){ $(".modal_ajax").submit(function() { var ourButton = this[0].name; document.getElementById('click').click(); if(ourButton == 'jobAdmin' || ourButton == 'jobRepairer' || ourButton == 'jobRetailer' ) { ajax_modal_other("includes/job_application.php",$(this)).done(function() { $(".modal_other").trigger("reset"); }); }else if(ourButton == 'user_reg'){ ajax_modal_other("includes/user_reg.php",$(this)).done(function() { $("#modal_other").trigger("reset"); return set_to_modal_other("includes/user_reg.php"); }); }else if(ourButton == 'user_login'){ ajax_modal_other("includes/user_login.php",$(this)).done(function() { $("#modal_other").trigger("reset"); return set_to_modal_other("includes/user_login.php"); }); }; return false; alert('ой... чтото пошло не так)'); return false; }); } function ajax_modal_other(what,where){ return $.ajax({ type: "POST", url: what, data: where.serialize(), cache: false, success: function(html){ $('#modal_other').html(html); } }); } function set_to_modal_other(what){ $("#target").submit(function() { ajax_modal_other(what, $(this)).done(function() { $("#modal_other").trigger("reset"); set_to_modal_other(what); }); return false; }); return true; } |
Форум | Правила | Описание | Объявления | Секции | Поиск | Книга знаний | Вики-миста |