Jump to content

Read file


elflacodepr

Recommended Posts

Or,

 

Create those "files" as javascript and then simply include them using a javascript SRC attribute. Besides, AJAX requires server-side code and you already stated you are only using client-side code.

 

Example:

 

main.htm

<html>
<head>
<script type="text/javascript">
window.onload = function()
{
    document.getElementById('events').innerHTML = eventsHTML;
}

</script>

<script src="events.inc.js"></script>

</head>
<body>
Here are today's events:
<div id="events"></div>

</body>
</html>

 

events.inc.js

//Create the events html code as a variable
//var eventsHTML;

var eventsHTML = '';

eventsHTML += '<ul>';
eventsHTML += '<li>Underwater basket weaving</li>';
eventsHTML += '<li>Naked decathalon</li>';
eventsHTML += '<li>Hula Hoop Football</li>';
eventsHTML += '</ul>';

 

Resulting page will show

==================

Here are today's events:

  • Underwater basket weaving
  • Naked decathalon
  • Hula Hoop Football

 

Of course, using javascript for something like this (including AJAX) is a poor solution. This really should be implemented server-side. But, you can also check if your server supports Server Side Includes (SSI) which will allow you to include an HTML file inside another HTML file.

Link to comment
Share on other sites

AJAX in no way requires server-side code.  AJAX requires server side code no more than Internet Explorer or Firefox does ;p.

 

Ah, yes. I was thinking about the "reading" of a file and didn't consider XML. You could, of course, read/parse an XML file with JavaScript. If there is a way to read/parse fiels with AJAX that are not XML, please elaborate. I still contend that a server-side language is the way to go due to cross-browser issue whenever dealing with javascript.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.