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

How to listen for GET requests instead of POST requests?

Solved by Anna View solution

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

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

3 months ago

Edit functionality has been restored!

❤️ 1

Suggested topics

Topic Participants Replies Views Activity
Support · by JakobDB, 17 hours ago
1 29 8 hours ago
Support · by ramenos, 2 days ago
3 56 13 hours ago
Support · by gravinator, 7 days ago
3 191 2 days ago
Support · by Roger Parkinson, 1 week ago
3 284 6 days ago
Support · by Marcel, 2 weeks ago
4 235 1 week ago