Запуск SQL-запроса после завершения AJAX

В настоящее время у меня есть 2 html выпадающих меню. Как только я выбираю один, он фильтрует данные в моей таблице HTML и отображает данные на основе выбора. Я также могу вносить изменения в каждую строку и, нажав кнопку «Сохранить», запустить запрос обновления, который обновляет таблицу. После запуска этого обновления я хочу, чтобы он повторно запускал тот же запрос, который использовался для фильтрации результатов в соответствии с выбором выпадающего списка, чтобы вы могли видеть самые последние результаты того, что вы выбрали после нажатия кнопки «Сохранить и запустить» обновить. Прямо сейчас вы можете видеть, что у меня есть window.location.href = window.location.href; под успешным обратным вызовом в моей функции AJAX, но это перезагружает всю страницу и запускает запрос по умолчанию, который отображается при загрузке страницы, так что это не работает для меня.

Все мои запросы, которые фильтруют результаты таблицы после выпадающего списка, находятся на моей странице dropdown-display.php которая вызывается, когда я что-то выбираю.

Выпадающие окна HTML:

 <form name="testForm" action=""> <select id="collector"> <option value="" selected="selected" disabled="disabled">Collector Name</option> <?php foreach($collect->fetchAll() as $name) { ?> <option class="choice" value="<?php echo htmlspecialchars($name['Collector Name']);?>"><?php echo $name['Collector Name'];?></option> <?php } ?> </select> <select id="date"> <option value="" selected="selected" disabled="disabled">Bill Date</option> <?php foreach($bill_date->fetchAll() as $date) { ?> <option class="choice" value="<?php echo $date['Date'];?>"><?php echo $date['Date'];?></option> <?php } ?> </select> </form> 

JavaScript (index.js):

 $(document).ready(function () { $('.save').click(function (event) { var $row = $(this).parents('tr'); var acct = $row.find('td[name="account"]').text(); var date = $row.find('td[name="date"]').text(); var checked = $row.find('input[name="selected"]').is(':checked'); var currency = $row.find('input[name="currency"]').val(); var datepicker = $row.find('input[name="datepicker"]').val(); var notes = $row.find('textarea[name="notes"]').val(); var paid = $row.find('input[name="paid"]').is(':checked'); var request = $.ajax({ type: "POST", url: "update.php", data: { acct: acct, date: date, checked: checked, currency: currency, datepicker: datepicker, notes: notes, paid: paid }, success: function(data){ alert('Row successfully saved'); //window.location.href = window.location.href; } }); }); }); 

И это мой javascript, который запускается в моем заголовке на главной странице index.php :

 function showUser(collector,date) { $('#billing_table').hide(); if (collector == "") { document.getElementById("txtHint").innerHTML = ""; return; } else { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("txtHint").innerHTML = this.responseText; var newTableObject = document.getElementById('billing_table'); sorttable.makeSortable(newTableObject); } } $.ajax( "dropdown-display.php" ,{ data:{ q:collector, data:date||undefined } } ).then( function(responseText){ $("#txtHint").html(responseText); sorttable.makeSortable($('#billing_table')[0]); } ,function(error){ console.warn("something went wrong:",error); debugger; } ) } } $(document).ready(function(){ $("#collector, #date").change(function(e){ showUser( $("#collector").val() ,$("#date").val() ); }); $("#collector").change(function(e){ $.post('index-ajax.php',{filter:'Name',by:$(this).val()},function(data){ $("#date .choice").hide(); $.each(data, function(key,row) { $("#date option").filter(function(i){ return $(this).attr("value").indexOf( row.item ) != -1; }).show(); }); },"JSON"); }); }); с function showUser(collector,date) { $('#billing_table').hide(); if (collector == "") { document.getElementById("txtHint").innerHTML = ""; return; } else { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { document.getElementById("txtHint").innerHTML = this.responseText; var newTableObject = document.getElementById('billing_table'); sorttable.makeSortable(newTableObject); } } $.ajax( "dropdown-display.php" ,{ data:{ q:collector, data:date||undefined } } ).then( function(responseText){ $("#txtHint").html(responseText); sorttable.makeSortable($('#billing_table')[0]); } ,function(error){ console.warn("something went wrong:",error); debugger; } ) } } $(document).ready(function(){ $("#collector, #date").change(function(e){ showUser( $("#collector").val() ,$("#date").val() ); }); $("#collector").change(function(e){ $.post('index-ajax.php',{filter:'Name',by:$(this).val()},function(data){ $("#date .choice").hide(); $.each(data, function(key,row) { $("#date option").filter(function(i){ return $(this).attr("value").indexOf( row.item ) != -1; }).show(); }); },"JSON"); }); }); 

Вы можете связать событие после успешного ответа ajax:

 $(document).ready(function () { $('.save').click(function (event) { var $row = $(this).parents('tr'); var acct = $row.find('td[name="account"]').text(); var date = $row.find('td[name="date"]').text(); var checked = $row.find('input[name="selected"]').is(':checked'); var currency = $row.find('input[name="currency"]').val(); var datepicker = $row.find('input[name="datepicker"]').val(); var notes = $row.find('textarea[name="notes"]').val(); var paid = $row.find('input[name="paid"]').is(':checked'); var request = $.ajax({ type: "POST", url: "update.php", data: { acct: acct, date: date, checked: checked, currency: currency, datepicker: datepicker, notes: notes, paid: paid }, success: function(data){ alert('Row successfully saved'); $('#chdir select').bind('change', getDirs); // this is use for example like change of select } }); }); }); function getDirs(){ //any functionality you want } 

Вам необходимо отправить фильтры (в свой Ajax-вызов) в качестве параметров на страницу, которая получает результат. Вы можете назвать их collector_sel и date_sel.

После того как обновление будет завершено, вы должны вернуть эти параметры.
Например, вы можете вернуть их в ту же строку GET, которую вы используете для window.location. HREF.

окно. место нахождения. href = "index.php? collector_sel = abc & date_sel = bcd"

Затем на странице, которую вы первоначально загрузите, сравниваются значения фильтра, чтобы снова выбрать их.

 <form name="testForm" action=""> <select id="collector"> <option value="">Collector Name</option> <?php $selected = ""; foreach($collect->fetchAll() as $name) { if (isset($collect_sel)){ if (strpos($_GET['collect_val'],$name['Collector Name'])==0) $selected = "selected"; } } ?> <option class="choice" value="<?php echo htmlspecialchars($name['Collector Name']);?>" selected="<?php echo $selected; ?>" ><?php echo $name['Collector Name'];?></option> <?php } ?> </select> // .... </form>