Simple AJAX view loading approach I'm writing my own MVC framework for learning purposes. Usually in my projects I like to use AJAX to send requests and retrive data. Now my doubt is if this can be a best approach to make a one page dashboard. 

I've created an .htaccess who will display only folders that have an index file inside, the dashboard will be loaded only after user login, the login form is on the index file who is inside a folder named user. On the root of the project there is another index file who will be publicy available.

Assuming I've this code in the user dashboard file:

HTML

&lt;div class="container-fluid" id="app"&gt;

    &lt;div class="row"&gt;

        &lt;div class="col-sm-12 col-lg-4"&gt;

            &lt;a href="#" id="open-settings"&gt;
            &lt;div class="card"&gt;
                &lt;div class="card-body"&gt;
                    &lt;div class="card-img-top text-center"&gt;
                    &lt;i class="fas fa-cog fa-3x"&gt;&lt;/i&gt;
                    &lt;/div&gt;
                    &lt;h5 class="card-title text-uppercase text-center"&gt;settings&lt;/h5&gt;
                &lt;/div&gt;    
            &lt;/div&gt;
            &lt;/a&gt;    
        &lt;/div&gt;

        &lt;div class="col-sm-12 col-lg-4"&gt;
            &lt;a href="#"&gt;
            &lt;div class="card"&gt;
                &lt;div class="card-body"&gt;
                    &lt;div class="card-img-top text-center"&gt;
                    &lt;i class="fas fa-database fa-3x"&gt;&lt;/i&gt;
                    &lt;/div&gt;
                    &lt;h5 class="card-title text-uppercase text-center"&gt;show database entry&lt;/h5&gt;
                &lt;/div&gt;    
            &lt;/div&gt;
            &lt;/a&gt;    
        &lt;/div&gt;

        &lt;div class="col-sm-12 col-lg-4"&gt;
            &lt;a href="#"&gt;
            &lt;div class="card"&gt;
                &lt;div class="card-body"&gt;
                    &lt;div class="card-img-top text-center"&gt;
                    &lt;i class="fas fa-plus fa-3x"&gt;&lt;/i&gt;
                    &lt;/div&gt;
                    &lt;h5 class="card-title text-uppercase text-center"&gt;new insert&lt;/h5&gt;
                &lt;/div&gt;    
            &lt;/div&gt;
            &lt;/a&gt;    
        &lt;/div&gt;
     &lt;/div&gt;
&lt;div class="row" id="display-view"&gt;&lt;/div&gt;
&lt;/div&gt; &lt;!-- container end --&gt;


What is the best approach to load the requested view for the user selected action?
I want to avoid duplication of the jquery code who now is something like this

$('#open-settings').on('click',function(e){
    e.preventDefault();
    preloader.modal('show');
      $.ajax({
        type: 'GET', 
        url: 'view/settings.php',
        cache: false,
        beforeSend: function(){
          preloader.modal('show'); 
      },
      success: function(response){
         $('#display-view').html(response) 
      }
  });
Without really knowing a great deal about how your code is structured and basing it purely on your ajax function you could so somethhing like this; 

function loadView(url, beforeSend, callback) {
    $.ajax({
        type: 'GET',
        url: url,
        cache: false,
        beforeSend: function(){
            beforeSend();
        },
        success: function(response){
            callback(response);
        }
    });
}


You could then use it like this

var showPreLoaderModal = function() {
    preloader.modal('show');
}

loadView("view/settings.php", showPreLoaderModal, function(response){
    $('#display-view').html(response)
});


But this is dirty the modern approach would involve promises!