viewsrc: return only body if page is requested via ajax

This commit is contained in:
Fabio Comuni 2012-03-28 11:42:04 +02:00
parent 0a2675d8b6
commit 767245e9ff
2 changed files with 10 additions and 1 deletions

View file

@ -563,6 +563,10 @@ function absurl($path) {
return $path; return $path;
} }
function is_ajax() {
return (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
}
// Primarily involved with database upgrade, but also sets the // Primarily involved with database upgrade, but also sets the
// base url for use in cmdline programs which don't have // base url for use in cmdline programs which don't have

View file

@ -25,7 +25,12 @@ function viewsrc_content(&$a) {
); );
if(count($r)) if(count($r))
if(is_ajax()) {
echo str_replace("\n",'<br />',$r[0]['body']);
killme();
} else {
$o .= str_replace("\n",'<br />',$r[0]['body']); $o .= str_replace("\n",'<br />',$r[0]['body']);
}
return $o; return $o;
} }