Using XML and AJAX with Epoch PrimeFollow this step-by-step Guide to set up Epoch Prime on your server. For the detailed Epoch Prime XML specification and guide, see the Epoch Prime XML specs page. For a detailed walkthrough of adding and removing dates, see the Dates in Epoch Prime page. You Will Need
Step 1. Embedding the XML data in your web pageXML, with its easy learning curve and flexibility, is quickly becoming the standard for sending data via the Web. Programming methods such as AJAX/AFLAX/etc all use XML to return data to the user's browser, and XML is the data format of choice for many inter-server operations. Currently the best way to embed XML in your pages is by placing it inside a JavaScript string constant (see below). For more (not necessarily recommended) methods, click here. XML as a JavaScript String (Preferred)Placing your XML into a JavaScript string is both standards-compliant and requires no special knowledge. It also makes it easier to pass the data in the string to Epoch Prime for initialization. This method works across all major browsers and is therefore the recommended method for embedding XML data in your web page.
Important: In order to avoid any "unterminated string literal/constant" errors, you must not have any line breaks in the XML string – the example above is formatted for easy reading. Standards junkies may want to put a "\" before the "/" in every tag (i.e. "<\/data>" instead of "</data>") to ensure full standards compliance. The major browsers will work with it either way. Step 2. Initializing Epoch Prime with the XMLOnce you have an XML string, it's easy to load it into Epoch Prime. Simply pass the XML string (or XMLDoc object, if already parsed) to Epoch Prime when you initialize the calendar and/or web page.
For more on Epoch Prime's initialization, see the Epoch Prime Constructor Reference. Step 3. Using XML After Epoch Prime is InitializedAfter the page is loaded, You can use AJAX to update the dates and/or configuration of Epoch Prime. To do this, you'll need to send a request to the server, using the XMLHttpRequest object. Once you've obtained an XML response from the server, you may pass responseXML or responseText to Epoch Prime's importXML() function. The calendar will then update its configuration and dates to the XML data's specifications.
Saving the State of Epoch Prime with AJAXOne of the most difficult problems encountered when using AJAX involves saving the state of a page after the user changes it. Epoch Prime introduces the outputAjaxQueryString() and exportXML() methods— condensing the Epoch Prime's current state into a single encoded HTTP URL string or XML string. You can then send the data server-side using your AJAX framework, or directly using the XMLHttpRequest object. Save data using outputAjaxQueryString():outputAjaxQueryString() is useful for sending simple calendar data, such as the currently selected date(s), to the server. It will create a URL-encoded string containing all the currently selected dates in the calendar, as well as calendar state variables such as displayYear and displayMonth—if the includeConfig argument is true. See the outputAjaxQueryString() Documentation for more details. <input type="button" value="Save Changes" onclick="saveChanges();"/>
Save data using exportXML()<input type="button" value="Save Changes" onclick="saveChanges();"/>
Example Code and DemoBelow is a fully-functioning demo of using XML with Epoch Prime. Try out the demo by changing the configuration, date types, and selecting different dates. When you're ready, you can paste the code below into an empty HTML file and gain some insight on integrating Epoch Prime into your site. DemoXML code used…And the Result:The calendar dates and configuration are updated real-time whenever you call importXML(). The XML format is the same whether you are passing it on page/calendar initialization, or by user actions after the page has loaded (via importXML()). Example CodeHere is some working example code you can use to paste into an empty HTML document. Don't forget to download the Epoch Prime Files and set the paths in the <script> and <link> tags in your new HTML file. This demo is written in XHTML, but will also work with the HTML doctypes.
Other Methods of Embedding XML in your pageDespite the growing populatity of XML, the W3C and major browsers have yet to come up with a deployable standard for embedding XML into web pages. As a result, some browsers have proprietary methods of embedding XML (see XML Data Islands in Internet Explorer). Here are 2 other ways to embed XML into your web page. Placing XML directly inside your page contentBecause most browsers ignore tags they do not recognize, it is possible to simply embed the XML directly in the page content. You can do this by creating a hidden <div> element and placing the XML inside it.
You can then access the XML data by accessing the <div> element's innerHTML JavaScript property:
The problem with this method is its complete lack of standards-compliance. While the major browsers can handle this method without problems, future versions may have stricter markup rules. We therefore recommend you do not use this method unless you absolutely have to. XML Data Islands (Internet Explorer Only)Internet Explorer introduces XML data islands as a way of embedding XML into page content. While useful, this method is not standards-compliant, and will not work for users running other browsers. You also need to be reasonably-familiar with XML data islands to implement this. Only implement this solution if you're sure your users run only Internet Explorer.
|