[pmwiki-devel] serving a part of a page by AJAX

Peter Bowers pbowers at pobox.com
Thu May 2 02:25:32 CDT 2013


I am putting together a web-site where the help is served in a jsquery-ui
dialog populated by AJAX.  Up until now I've coded the help in HTML and
just put it directly in PHP variables.  As the site matures the
documentation is growing rapidly and maintaining it in HTML is getting a
bit onerous -- it would be great if I could maintain the docs in pmwiki.

In order to serve just the page text I've created an action handler.  I
could totally replace HandleBrowse() if necessary, but it feels like I
should be able to just set a couple configuration variables and re-use that
functionality.

When I do this:

===(snip)===
function HandleAJAXPageText($pagename, $auth = 'read')
{
    global $HandleBrowseFmt;
    $HandleBrowseFmt = array('function:PrintJSON($PageText)');
    HandleBrowse($pagename, $auth);
}

function PrintJSON($pagename, $out)
{
    header("Content-type: application/json");
    print json_encode($out);
}
===(snip)===

The $PageText ends up getting replaced by the contents of the web-page and
then the 'function:PrintJSON(hello this is the text on the page)' no longer
matches the regex for a valid function and the function is never called.  I
end up getting a web-page that includes the PrintJSON( ... ) function call
as part of the text on the page served.

(The relevant part of pmwiki code is in pmwiki.php around line 1182 - in
the PrintFmt() function.)

I tried various ways of getting the 'function:PrintJSON(...)' to pass the
variable $PageText rather than the contents of it, but I'm not making any
progress...

Any ideas?

-Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.pmichaud.com/pipermail/pmwiki-devel/attachments/20130502/e20150fe/attachment.html>


More information about the pmwiki-devel mailing list