Page 1 of 1

Is it possible to turn off layout only for ajax request?

Posted: Thu Jun 05, 2008 9:49 am
by szimek
Hi,

I got few pages that I'd like to make accessible for ajax and non-ajax clients. If user with js enabled clicks a link, I'd like to fetch a page (content *without* the layout) and display it in a div.  However, if user has js disabled, it should normally return the whole page (content *with* layout).

Is it possible to do wth CMS MS?

Regards

Re: Is it possible to turn off layout only for ajax request?

Posted: Thu Jun 05, 2008 1:29 pm
by calguy1000
try adding showtemplate=false to the url, or cntnt01showtemplate=false

Re: Is it possible to turn off layout only for ajax request?

Posted: Mon Jun 09, 2008 7:59 am
by piotrekkr
for example :):
$this->CreateLink($id, 'action', $returnid, '', array('showtemplate' => 'false'), '', true);

Re: Is it possible to turn off layout only for ajax request?

Posted: Mon Jun 09, 2008 12:56 pm
by calguy1000
No, this solution should work in 1.2.x as well.

Re: Is it possible to turn off layout only for ajax request?

Posted: Tue Jun 10, 2008 10:34 am
by piotrekkr
My solution work in 1.0.5 too :)

Re: Is it possible to turn off layout only for ajax request?

Posted: Fri Jul 18, 2008 7:54 pm
by NaN
So far...
But what about Modules in the backend?
I try to create a simple mailer module that sends emails to users of the FrontendUsers module.
To prevent a server timeout I try to send the mails in multiple requests with ajax (similar to the NewsletterMadeSimple module).
My ajax request does not call an external php-file to send the mails. I'm using the moduleinterface.php with an action.sendMail.php instead. (e.g. the url that will be requested by the ajax script is moduleinterface.php?mact=MyModule,m1_,sendMail,0...) I believe this makes it more secure.
My problem is, that the response of the server contains the whole backend template.
But I just need an id...
The "showtemplate" param seems only to work for the frontend.
Is there any possibilty to realize an ajax request via backend without opening a new window? (like NMS)

(By the way: I don't want to use AJAX MadeSimple 'cause i've got my own very simple ajax request and i don't want my module to depend on more than the CMSMailerModule and FrontendUsers.)

Any ideas?

Re: Is it possible to turn off layout only for ajax request?

Posted: Sat Jul 19, 2008 1:58 am
by NaN
Looking in the moduleinterface.php i found this:

Code: Select all


$USE_THEME = true;
if( isset( $_REQUEST[$id . 'disable_theme'] ))
{
	$USE_THEME = false;
}
else if( isset( $_REQUEST['disable_theme'] ))
{
	$USE_THEME = false;
}

So i just need to add the param disable_theme to my ajax request.
Quite simple.
But the response from the server still contains some comments, , and .
I have to modify the response via the javascript function replace().
So my request seems to work now.
But this cannot be a proper solution.
Is there any way to get just a single value as response from the moduleinterface.php?

Re: Is it possible to turn off layout only for ajax request?

Posted: Sat Jul 19, 2008 4:36 pm
by NaN
When searching for that output i found some "issues" in the moduleinterface.php, header.php and footer.php.
It is hardcoded there:

moduleinterface.php line 139:

Code: Select all


if (!$suppressOutput)
{
	echo '</div>';
}

header.php line 10:

Code: Select all


if (isset($USE_THEME) && $USE_THEME == false)
  {
    echo '<!-- admin theme disabled -->';
  }

footer.php line 2 and 28-33:

Code: Select all


if (isset($USE_THEME) && $USE_THEME == false)
  {
    echo '<!-- admin theme disabled -->';
  }

...

?>

<__body>
</__html>

<?php

...



I just uncommented/modified it:

moduleinterface.php:

Code: Select all


# modified by NaN since we don't want ANY output from the admintheme if $USE_THEME == false
if (!$suppressOutput && isset($USE_THEME) && $USE_THEME!=false)
{
	echo '</div>';
}

header.php/footer.php:

Code: Select all


if (isset($USE_THEME) && $USE_THEME == false)
  {
	  # commented out by NaN since we don't want ANY output from the
	  # admintheme if $USE_THEME == false
	  # echo '<!-- admin theme disabled -->';
  }

...

if (isset($USE_THEME) && $USE_THEME != false)
{
	# modified by NaN since we don't want ANY output from the admintheme
	# if $USE_THEME == false
	echo "<__body>\n</html>";
}

Dunno if this is usefull but just in case...

Re: Is it possible to turn off layout only for ajax request?

Posted: Mon Jul 21, 2008 6:31 am
by oi_antz
Here's how I did it:

file: modules/FEUsers/ajax_cities_for_country.php

Code: Select all

<?php
while(ob_get_level()>0) ob_end_clean();

header('Content-type: text/javascript');
die(json_encode($cities));