I got to read a number of HTML files, get its tags content and generate a report using these contents (e.g day1.html has Simon, I need to read day1.html file, and get 'author' div content which is 'Simon' and generate my own report using this data). How can I do it using Javascript? any help is highly appreciated. Many thanks. An
-
1Client-side JavaScript accessing HTML files on a web-server, or server-side JavaScript accessing files from the file system, or...?nnnnnn– nnnnnn2012-12-10 04:33:22 +00:00Commented Dec 10, 2012 at 4:33
-
it is server-side java script. yesterday my friend suggested me using AJAX, still working on searching :(justmobileapps– justmobileapps2012-12-11 03:11:46 +00:00Commented Dec 11, 2012 at 3:11
-
If it's server-side JS (node.js?) you wouldn't use Ajax: Ajax is a way for JS in the browser to make a request to the web-server without reloading the current page. Is a request from a web browser involved at all in your requirement?nnnnnn– nnnnnn2012-12-11 03:49:50 +00:00Commented Dec 11, 2012 at 3:49
-
My problem is: I am about to make news blog page for my project, We have a html(or xml) file called "blog.html(or .xml)", this file defines title, author, content for each post of the blog(like <DIV id="author">Simon</DIV> <DIV id="title">New blog</DIV> <DIV id="content">Content bla bla bla</DIV> , webadmin can also update this file later). My job is to read this file, get details and out put to jsp page. many thanks for your reply :)justmobileapps– justmobileapps2012-12-11 04:56:58 +00:00Commented Dec 11, 2012 at 4:56
Add a comment
|
1 Answer
If you're not adverse to using jQuery you can use get() to load and parse an HTML document via JavaScript:
jQuery.get('day1.html', function(html)) {
var author_div_text_content = jQuery('DIV#author', html).text();
}
A sample working on the jsFiddle web site:
1 Comment
justmobileapps
I ll try to work on this way you showed me, yesterday my friend suggested me using ajax and I am still googling it. maybe yr method would work out.many tks.