Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Support

How to listen for GET requests instead of POST requests?

Solved by Anna View solution

Started by Anna 2 days ago · 2 replies · 55 views
2 days ago

Trying to incorporate a third party script in a plugin. On page load it sends a GET request to a page/uri of my choosing, which I would like to answer. However, I only know how to do this for POST requests:

PHP
public function onPagesInitialized(Event $event) {
    $uri = $this->grav['uri'];
    $page = $this->grav['page'];
    $this->ajax_url = "/a-specific-non-page-uri";

    if ($this->ajax_url && $this->ajax_url == $uri->path()) {
        echo "now I can handle the POST request";
    }
}`

This works perfectly, but not for GET requests. How do I catch those in Grav? If anyone knows another plugin with something like this, I would love to take a peek!

14 hours ago Solution

It seems I can neither edit nor delete this. Oh well, here’s the solution: I was confused about a different thing and this works perfectly fine. 😆

Can’t mark it as solved either?

8 hours ago

Edit functionality has been restored!

Suggested topics

Topic Participants Replies Views Activity
Support · by Thomas, 1 week ago
2 50 5 hours ago
Support · by Justin Young, 9 hours ago
1 24 8 hours ago
Support · by Duc , 1 week ago
2 59 5 days ago
Support · by Colin Hume, 1 week ago
2 52 5 days ago
Support · by Lyn Borchert, 1 month ago
5 158 2 weeks ago