0

I have a bootstrap form in the bootstrap modal. I have 2 dependent fields. So 2nd field dropdown is based on the first field value.

What I want to do is when I select the value from the first field, ajax request triggers and select the related vales for second field.

It all works at the moment, but on the success of Ajax request, i have to refresh the page and re-open the modal.

How it is possible to refresh the content of modal.

As you can see below, in success, I have to refresh the page and re-trigger the modal.

Here is my jquery ajax.

$("#add-new-group").click(function(e) {
e.preventDefault();
//Create ajax request with the two paramaters
$.ajax({
    url: '/',
    type: 'POST',
    data: $("#new-group").serialize(),
    success: function(data, textStatus, jqXHR) {
        jQuery('#stock').load('/tasks/stock.php');
        $('#add-new-category-modal').modal('hide');
        jQuery('#stock').load('/tasks/stock.php',  function()  {
            $("#stock-settings").removeClass("collapse");
            $(".add-new-category").trigger("click");
        });
    },
    error: function(jqXHR, textStatus, errorThrown) {
        //Display error message to user
        alert("An error occured when saving the data");
      }
  }); // End ajax request
 }); // End on click event

0 Answers0