Skip to content
Grav 2.1 is out: every page speaks Markdown. Read the announcement →

How to listen for GET requests instead of POST requests?

Solved by Anna View solution

Started by Anna 3 months ago · 2 replies · 426 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 blu3prince, 3 days ago
1 61 2 seconds ago
Support · by complanar, 6 days ago
6 152 1 day ago
Support · by Rick Beebe, 6 days ago
2 112 3 days ago
Support · by alex, 5 days ago
2 100 4 days ago
Support · by Marcel, 2 weeks ago
1 151 4 days ago