Skip to content Skip to sidebar Skip to footer

Running Sql Query After Ajax Completes

I currently have 2 html dropdowns. Once I select from one, it filters the data in my HTML table and displays data based on the selection. I can also make changes to each row and, b

Solution 1:

You can bind the event after successful response of ajax like that:

$(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 
        }
      });
   });
});

functiongetDirs(){
  //any functionality you want
}

Solution 2:

You need to send the filters (in your Ajax call) as parameters to the page that gets the result. You could name them collector_sel and date_sel.

Once the update has been completed, you must return these parameters. For example, you could return them in the same GET string you use for window.location. href.

window. location. href = "index.php?collector_sel=abc&date_sel=bcd"

Then on the page you initially load it compares the filter values to select them again.

<formname="testForm"action=""><selectid="collector"><optionvalue="">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";      
                }              
             } ?><optionclass="choice"value="<?phpecho htmlspecialchars($name['Collector Name']);?>"selected="<?phpecho$selected; ?>" ><?phpecho$name['Collector Name'];?></option><?php } ?></select>

// ....
</form>

Post a Comment for "Running Sql Query After Ajax Completes"