<br /> function getHeader($header) {<br /> if (empty($header)) {<br /> ;<br /> }<br /><br /> /* Pokusiť sa ich najpr získať z globálneho poľa $_SERVER. */<br /> $temp = ’HTTP_’ . strtoupper(str_replace(’-’, ’_’, $header));<br /> if (!empty($_SERVER[$temp])) {<br /> return $_SERVER[$temp];<br /> }<br /><br /> /* Toto vyzerá ako jediné riešenie ako získať Authorization header na Apache serveri. */<br /> if (function_exists(’apache_request_headers’)) {<br /> $headers = apache_request_headers();<br /> if (!empty($headers[$header])) {<br /> return $headers[$header];<br /> }<br /> }<br /><br /> return false;<br /> }<br /><br /> function isXmlHttpRequest()<br /> {<br /> return ($this->getHeader(’X_REQUESTED_WITH’) == ’XMLHttpRequest’);<br /> }<br />
You could have used the index-ajax.php from Modx to do the same thing without hacking into the core.
Look at how the ajaxsearch snippet works.
I never use index-ajax.php or any other custom ajax processor. MODx delivers Ajax requests from documents just fine; you simply select no template and make sure the document returns only what you need. MODx definitely supports this now, and I’d never do it any other way.
Hi,
Isn’t true
In the "full MODx API solution" the ajax request is setting up with : new Ajax("[~22~]",{
In the "lightweight" solution: new Ajax(’index-ajax.php’, {postBody: pars, update: $(’card’) }).request();});
In the first solution you set up your ajax request with index.php and you call the MODx parser method to build the answer. In the second solution you set your ajax request with index-ajax.php and you call only the initialisation of database Variables. So you need to initiate a new document parser to use the global $modx and populate the $modx->documentMap array with:
In either I don’t get only content, the target of my effort is obtain only content without template of any document and this MODx parser doesn’t support now.
you simply select no template and make sure the document returns only what you need. MODx definitely supports this now, and I’d never do it any other way.
<br />Home - home<br />Blog - blog<br />Products - products<br />About Us - about-us<br />
<br />Home - home-ajax<br />Blog - blog-ajax<br />Products - products-ajax<br />About Us - about-us-ajax<br />
Like opengeek says, MODx already supports this now (it’s been working on my site since 0.9.6.)
What you need is another page on your site that contains the content that you want to be placed on-screen.
For example, on one of my sites I had a "comments" feature so people could write comments on some of my pages (like a blog.) When the user hit "Add Comment", MODx sent an Ajax request to a page which processed the comment (added to the databse) and sent back "thank you for submitting your comment..." This content then replaced the "Add Comment" form on the page.
The page that handled the post was in a designated "Ajax" container in MODx, with no template (or a template that simply has [*content*] in it.)
Thinking about, you could probably use the template switcher plugin to achieve the same effect with a single page if you’re worried about duplicating content.
The 2 options are thus (unless anyone else knows of any others):
- Use opengeek’s (and my) suggestion and all the parts of the page that need to be ajax-ified, have a separate page with no (or minimal) template that only returns the content
- Use my suggestion and have TemplateSwitcher dynamically change the template of page’s called via Ajax to te blank/minimal template
If you cannot use TemplateSwitcher for the caching issue (and it’s that big a hit on your system) then you’re stuck with creating duplicate pages.
Of course you could always put all the content on the page into a chunk, and have the 2 pages (Ajax and non-Ajax) call the chunk to get the content, thus eliminating the duplicate content issue.
From a personal point of view, I don’t see this a fit use of Ajax (updating entire pages of content.) Users will be unable to bookmark your pages - if they land on the blog (non-Ajax) page and navigate around, they’d still wind up with the blog URL in their address bar - confusing. The back button (possibly) won’t work. JavaScript doesn’t execute when it’s passed back in your Ajax method.
Heaps of problems... I think Ajax is best left to what it does best - background-loading, checking, and updating parts of pages.