Reputation: 61
I am currently developing a web site which basiclly shows the sensor datas. The site must have a chart and I suppose to use HighChart line chart. Because of the website hasn't too much contents, I decided to make all the action one page (graphs, tables...). So this page has lots of parts. To avoid this clutter, I want to build graph part in another HTML file and via JQuery load function, use this in the main page. The only way that I know how to show or use the other codes is this.
For example:
$('.sampleDiv').load('sampleHtmlFile');
And the problem begins. I am not sure whether this way influence the whole page and its well designed structure. Is it bad practice for a developer? Are there any reason to or not to use load function like this way? Maybe another way to handle this problem...
By the way, I am too new for Web Development.
Upvotes: 0
Views: 1272
Reputation: 4481
I would not recommend to use jQuery's load
to load web-pages that depend on javascript
(I assume you want to use http://www.highcharts.com/).
specially as a beginner you will run into a lot problems doing this.
more info:
.load()
is nothing else than an ajax call - and you run into problems loading new javascript
scripts to the page via ajax.
the browser can't handle loading scripts via ajax by itself correctly so the browser handles the request like it was synchronous and you'll receive this warning:
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience.
to prevent this you'll need something like jQuery.getScript()
to load external javascript files with .load()
.
TL;DR:
I wouldn't recommend to load html files which include external javascript files when you are a beginner. you can get get into a lot of troubles - from missing dependencies into browsers handling the ajax requests like synchronous requests.
Upvotes: 1