Reputation: 271
I have an web page which displays data selected by a category. The categories are listed in one page (categories.html) and the data is shown in another page (list.html).
Instead of reloading the whole page (list.html) to display the data whenever a new category is selected I want to write a public method which can be called from (categories.html) so that only the data is fetched alone but not the whole list.html page again.
I'm using HTML5 + JS + CSS (JS as in jQuery and Dojo). Is this scenario possible?
I cannot combine both categories.html and list.html as a single file, as I have multiple list.html files for displaying various data for the selected category.
Thanking You in advance...
Upvotes: 0
Views: 87
Reputation: 2503
You can use $.get or .load with jquery to get remote html content
$('#containerDiv').load('list.html')
or
$.get( "list.html", function( data ) {
$('#containerDiv').html( data );
});
Upvotes: 1
Reputation: 1781
from javascript alone I don't think you can do this but you can use any server side language you like for example php
.
first you have to bind the click event or any event which is triggered when category is selected and in that event's callback you can use jquery ajax method to call the php
script. You have to pass the desired data for example the category name selected to the php script through ajax. Now you can create a html
snippet file if you want to simply append data to list.html
.
in the js script for list.html
you can put an interval that will check for the for the snippet file after say 1/2 seconds and use jquery get
or load
ajax methods to fetch the snippet code and add it to 'list.html'
Upvotes: 1