0

I try to load a entry after a button is clicked, currently my code looks like this:

This is generating a 404 error. Dunno why?

<?php
/**
 * PopUp plugin for Craft CMS 3.x
 *
 * test
 *
 * @link      https://digitalwunder.io
 * @copyright Copyright (c) 2020 digitalwunder.io
 */

namespace digitalwunder\popup;


use Craft;
use craft\base\Plugin;
use craft\services\Plugins;
use craft\events\PluginEvent;
use craft\web\UrlManager;
use craft\events\RegisterUrlRulesEvent;

use yii\base\Event;

/**
 * Class PopUp
 *
 * @author    digitalwunder.io
 * @package   PopUp
 * @since     0.0.1
 *
 */
class PopUp extends Plugin
{
    // Static Properties
    // =========================================================================

    /**
     * @var PopUp
     */
    public static $plugin;

    // Public Properties
    // =========================================================================

    /**
     * @var string
     */
    public $schemaVersion = '0.0.1';

    /**
     * @var bool
     */
    public $hasCpSettings = false;

    /**
     * @var bool
     */
    public $hasCpSection = false;

    // Public Methods
    // =========================================================================

    /**
     * @inheritdoc
     */
    public function init()
    {
        parent::init();
        self::$plugin = $this;

        Event::on(
            UrlManager::class,
            UrlManager::EVENT_REGISTER_SITE_URL_RULES,
            function (RegisterUrlRulesEvent $event) {
                $event->rules['siteActionTrigger1'] = 'pop-up/default';
            }
        );

        Event::on(
            UrlManager::class,
            UrlManager::EVENT_REGISTER_CP_URL_RULES,
            function (RegisterUrlRulesEvent $event) {
                $event->rules['cpActionTrigger1'] = 'pop-up/default/do-something';
            }
        );

        Event::on(
            Plugins::class,
            Plugins::EVENT_AFTER_INSTALL_PLUGIN,
            function (PluginEvent $event) {
                if ($event->plugin === $this) {
                }
            }
        );

        Craft::info(
            Craft::t(
                'pop-up',
                '{name} plugin loaded',
                ['name' => $this->name]
            ),
            __METHOD__
        );
    }

    // Protected Methods
    // =========================================================================

    public function actionCheckStatus()
    {
        $this->requireAcceptsJson();

        $response = [
            'status' => 'open'
        ];

        return $this->asJson($response);
    }

}

And the script like this

    <script type="text/javascript">
      $('#test').click(function(e){
        e.preventDefault()
        var x = {{ entry.id }};
        $.ajax({
            'type': 'post',
            'contentType': 'application/x-www-form-urlencoded; charset=UTF-8',
            'cache': false,
            // 'data': data,
            'url': '/actions/pop-up/checkStatus',
            'dataType': 'json',
            'timeout': 50000
        }).done(function (response) {
          console.log(response);
            // Success
        }).fail(function (error) {
           // Total fail.
        });
      });
    </script>

Can anyone see why I get a 404 error?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.