Skip to content
● Grav 2.2 is out: 2x faster cold starts and 96% less memory on big sites. Read the announcement →

How to listen for GET requests instead of POST requests?

Solved by Anna View solution

Started by Anna 4 months ago · 2 replies · 518 views
4 months 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!

4 months 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?

4 months ago

Edit functionality has been restored!

❤️ 1

Suggested topics

Topic Participants Replies Views Activity
Support · by webmasterodp, 7 days ago
4 152 6 days ago
Support · by nwhitfield, 1 week ago
2 131 1 week ago
Support · by stell, 3 weeks ago
5 366 2 weeks ago
Support · by gravinator, 1 month ago
5 557 2 weeks ago
Support · by Gravver, 3 weeks ago
6 344 3 weeks ago