1

I'm working on a project using Electron technology to make a desktop app with a local database where I have a navbar and I want to refresh the content of the main section without refresh the whole page.

I know there's ajax but with ajax I should use a web server, so I think that the user should have a web server on his machine to refresh, is there's a way to refresh without a server or to create a "virtual" server with JavaScript please?

I've tried this but it work just with a web server:

$(document).ready(function() {
  $(function() {
    $('#ideal_form').submit(function(e) {
      e.preventDefault();
      var form = $(this);
      var post_url = form.attr('action');
      var post_data = form.serialize();
      $('#loader3', form).html('<img src="../../images/ajax-loader.gif" />       Please wait...');
      $.ajax({
        type: 'POST',
        url: post_url,
        data: post_data,
        success: function(msg) {
          $(form).fadeOut(800, function() {
            form.html(msg).fadeIn().delay(2000);

          });
        }
      });
    });
  });
});
j3ff
  • 5,719
  • 8
  • 38
  • 51
Ilyass
  • 35
  • 6

1 Answers1

1

The code you posted seems pretty irrelevant, and a copy from another stackoverflow post (https://stackoverflow.com/a/21135348/1833503). In your comment you say that you want to load a static HTML file for the new content of a div when a menu item is clicked.

I recommend taking a look at https://api.jquery.com/load/. You might need something like this:

$("#about-button").click(function() {
  $("#content").load("about.html");
});
Micha Schwab
  • 786
  • 1
  • 6
  • 21
  • Yes sir , i used Sqlite3 as a database , i have a menu , like Home , About , Contact us .. , i want when i click About ;the main section load a new content from a new html file without refreshing whole the page , and without using a web server . Thank u for your help – Ilyass Apr 04 '20 at 13:19
  • Sorry, that's still not enough information. What is the content you want to display when you click the about button? Does that content live in the sqlite database? If so, how do you want to query it? – Micha Schwab Apr 04 '20 at 14:06
  • Aw okay sorry bro ! the content is a static html file , the database is just to login ,it means when i click the about button; a static html file should load into a div section , and when i click another button like Contact us another html file should load into the div section . – Ilyass Apr 04 '20 at 14:23
  • Ok. Since you want to load a static HTML file, you do need to use AJAX. I updated my answer. Please see if that helps. – Micha Schwab Apr 04 '20 at 14:43
  • yes bro i have tried to use load with jquery but it works just with a web server , i don't want to use a web server . thank you so much. – Ilyass Apr 04 '20 at 15:04