Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

How to listen for GET requests instead of POST requests?

Solved by Anna View solution

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

5 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?

5 months ago

Edit functionality has been restored!

❤️ 1

Suggested topics

Topic Participants Replies Views Activity
Support · by TomW, 2 weeks ago
8 227 8 hours ago
Support · by alex, 2 months ago
8 667 23 hours ago
Support · by Supple, 5 days ago
1 98 1 day ago
Support · by TomW, 1 week ago
3 159 3 days ago
Support · by TomW, 6 days ago
2 106 5 days ago