jquery - Load HTML Snippets into DOM -


i'm trying come best way maintain site lots of pages, , i've opted create separate html files "common" html elements header , footer.

currently, index.html page set this, jquery function supposed inject contents of text.html footer div.

<html> <head> <title>test site</title> <script src="jquery-1.8.3.min.js" type="text/javascript"></script> <script type="text/javascript">     $(function () {       $("#footer").load("text.html");     }); </script> </head> <body>     <div id="footer"></div> </body> </html> 

the contents of text.html are:

<div style="red">     hello, world! </div> 

this doesn't seem work , getting following error

xmlhttprequest cannot load file:///users/jon/desktop/text.html. origin null not allowed access-control-allow-origin

question: possible via jquery, or have use php/something else? know wordpress similar, i'm pretty sure use php. method sustainable if can work.

you can't load file:// urls in browsers via ajax requests or origin null not allowed access-control-allow-origin. believe firefox let you, chrome/safari don't. ( see google chrome --allow-file-access-from-files disabled chrome beta 8 more)

the easiest thing run local webserver, won't error.

also, in terms of doing, there nicer libraries jquery. i'm using https://github.com/linkedin/dustjs/wiki/reusable-ui-dust-modules - similar how define mustache partials in html? - both have partials/includes of other files. @ http://pagerjs.com/

one other project worth checking out http://docpad.org/ - install webserver you. once finished working on site, can generate static html parts.


Comments

Popular posts from this blog

Pull out data related to my apps from Android Play Store and iOS App Store -

Change php variable from jquery value using ajax (same page) -

How can I fetch data from a web server in an android application? -