AJAX requests in web site template Jun18 '06
JavaScript let’s you send data with the xmlhttprequest object, using a full-length URL, such as this:
mypage.php?today=Sunday&sky=blue&weather=80
You’ll recognize this URL from any development work you do - it simply contains variables that are passed from one page, to the next.
With JavaScript, you can request this URL, which then connects to the server, and runs through any processes on that page (mypage.php).
However, if your web site is set up as a template (possibly with mod_rewrite, which could redirect every request to one page), you may have an issue with this.
A template means that you have one page that contains the static HTML, such as <head> tags, <body> tags, and possibly the DOCTYPE, and other stuff that doesn’t change - or, at least, is consistent amongst all pages in your web site.
Every page requested on your site uses that template page, and simply fills in the content, based on the request.
This is a very good way to setup a web site, but you may run into problems when using AJAX.
Any AJAX requests (within your site template) will have the HTML tags surrounding the XML.
So, you’ll have something like this:
<html>
<head>
</head>
<body>
<responseXML>
<result>Query result</result>
</responseXML>
</body>
</html>
An XML file (a valid XML file) can’t (and shouldn’t) have all the HTML included in it. This makes parsing it much more cumbersome, and it’s just not the right way to do it.
To get around this, you’ll need to request a file that’s not part of your template structure.
I’m open to ideas on this.
The only quick thing I can think of is requesting a file that’s off the server - possibly another domain, which could "house" AJAX request pages. This is probably not the best approach, since if that site goes down for some reason, all other sites are affected.
Categories: JavaScript
, Web Development
, XML ![]()
Add Feedback (view all)
Leave feedback
Yes. In fact, every request that does actually exist as a path (ie: mydomain.com/documents/expenses.doc) should b ... Read more.
matthom
is published and produced by Matt Thommes - an independent publishing enthusiast, mobile blogger, content creator, informative writer, web developer from a suburb of Chicago.
Never one to conform, Matt intends to promote the effect the web has on our lives, in an effort to intensify, instruct, and clarify all that is happening around us.
Popular Pages
- Fast rounded corners in Photoshop (7873 recent visits)
- PHP – passing variables across pages (2857 recent visits)
- JavaScript set selected on load (2345 recent visits)
- Removing all child nodes from an element (1704 recent visits)
- iPod songs out of order? (1412 recent visits)
- Firefox 3 smart address bar: wildcard search (1300 recent visits)
- Britney - Everytime piano tab (1180 recent visits)
- MySQL LEFT JOIN syntax (971 recent visits)
- Breathe Me - Sia (824 recent visits)
- Tumblr: how blogging should be (727 recent visits)
Similar Entries
- PITT article: web-based feed readers (2 recent visits)
- Developing web applications: operational means beta (2 recent visits)
- How do web sites work? (Part 1, Series A) (17 recent visits)
- How do web sites work? (Part 2, Series A) (33 recent visits)
- WEGO – The Web Ego project (4 recent visits)
- Yahoo! Web Services: Image Search (2 recent visits)
Stats
24 unique visits since August 2008
Recent Referrers (click)
- ajax template
- how to tumblr templates
- ajax web template
- ajax site templates
- ajax templates
- ajax site template
- ajax site template
- ajax web template
- Ajax website templates
- ajax templates
- ajax template
- ajax templates
- php ajax templates
- ajax web templates
- ajax templates
- ajax template website
- website using ajax templates with php
- ajax web template
Well it depends on how your template system works. Can’t you tell it to only work on certain files or folders or filename patterns? Or to e ... Read more.