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
https://forums.phpfreaks.com/topic/149555-read-file/#findComment-786259
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
https://forums.phpfreaks.com/topic/149555-read-file/#findComment-786449
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.