store html data for dynamic ajax loading - html

I have a site on which Im trying to dynamically update the index.html page, replacing content held in a div, with new html content gathered from an AJAX request to a server holding my other html data. My question is how should I store my html on the server side. Should i create new html files with the content in the body, and try to extract the html from the body? Or Should I try to somehow store just the (div with a few elements inside) fragment I want to use?

You can just store the div and its contents in an external file, load it with ajax, and put the loaded content inside your main html file. Give a look into this exemple to see how to do it.

Related

Is it possible to create an internal html page to my index.html?

I'm creating a new website and I will have different pages on it. However, instead of creating new HTML files for each page and an anchor for each, I want all my pages contained in one HTML file. Is it possible in any way?
You can try Vue js or React js or many js frameworks ... which contain components.
Using HTML
You can control HTML page section how tabs working in HTML, take a look in Bootstrap Tabs, or you can hide/show sections using CSS or using JS, you may store HTML for each page in array of js and load that HTML to Body based on URL you create
Using Server Side Language
Also if you need single page application with multiple pages you need a Server Side language, where Database contains your website configurations and you can load based on the URL each page's layout or text like heading forms etc...

Programatically modifying a HTML page from ASP.NET

I have an ASP.NET web app with a standard default.aspx, from within which I need to load a html page from another site (all internal intranet) and pre-populate form input controls on that loaded html page using ASP variables. Specifically, username / pwd on a login form based user details loaded by the aspx from a db. The html page also contains a considerable amount of js (shouldn't directly impact this question though).
Not sure of the best route to approach this. I have considered:
1. Loading the html page in a frame, then somehow manipulating it's DOM from another frame loaded from the aspx.
2. Loading the html during aspx page load or render, then replacing the relevant sections of the html with the new values.
I have had a stab at both approaches and ran into issues. With (2) the resulting HTML isn't recognized as HTML by the browser at all (despite the written response being just the original html relayed from the original site). I can see the HTML source in the browser, but the page itself appears blank.
Answers warmly anticipated. Thank-you.
1.if you want to go wityh iframe
You can easily modify values from communicate between parent window and iframe
from parent to iframe function
document.querySelector('iframe').contentWindow.ChildFunction(33);
from chhild to parentfunction
parent.parentfunction("4rom child")
make a function in iframe that accept an object (from parent) and populate it in.
make a function in parent that accept an object (from child) .
2.how are you "Loading the html during aspx page load or render,"
- ajax or something else?
-making a user controll
both should work fine .
( could you tell how are you loading html ?)(as it should have worked)

Generate content with servlet into iframe which is inside another html

I'm learning Servlet now, and I was wondering if it is possible to generate 2 html content at once. I would like to generate an html page which is holding an iframe which also has a content. Is it possible to load 2 html page at once in Servlet?
yes this is completely possible. All you have to do is complete your code for html page which is going to be displayed in the iframe.
Now in servlet you have to write the html code for displaying and call the iframe in servlet.
So when your servlet will run on the server it will be running html code of servlet + iframe (which is displaying another html content)

render static content of html page using text file

I have a scenario where I need to create simple html page having large amount of text.So i want to make use of some text file,which I can have in my content folder of mvc vb.net solution.so next time,if i want to change my content ,I can change in that text file only.I can only use java script and html to achieve this.
I tried using java script to load file and that is not working.
You can solve it via JavaScript but in a very crude way. Yuo would need to write a script that requests the text file via AJAX and then puts the resulting content into a specific tag on the current page.

How to make an html id defined in an html accessable in another html file

How can I let an id that is defined in an html or jsp file be accessable in another file?
The reason for doing this is that I used Ajax to get some content that is defined in another file. And I want the id of that content to be accessable from my first file.
I tried to look for a way to change the scope of the id but couldn't find.
Normally you can't.
But you could create an iframe from your html page and load the file that you want to access. either make the iframe hidden or of no size.
Here is a post that mentions how to do access id's like that:
Access child iFrame DOM from parent page