Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2018-11-11 21:39:00

richtestani
Plugin Author
Registered: 2009-11-08
Posts: 128

JSON response through TXP plugin event

What’s the proper way to make an ajax (http) request to the TextPattern admin?

When I make a request to `?event=my_event_name&step=my_ajax_step`

The whole page is returned. How can I return just my json resopnse? I can create a new file to make a request so, but there are bunch of functions to reuse in the plugin file.

Thanks
Rich

Offline

#2 2018-11-11 21:55:06

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: JSON response through TXP plugin event

Try adding &app_mode=async to your request. In the plugin code you’d put then something like

global $app_mode;

if ($app_mode == 'async') {
    $response = '"JSON string"'; // or array/object
    send_json_response($response);

    return;
}

Offline

Board footer

Powered by FluxBB