We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39521
    • 15 Posts
    I'm trying to figure out how to do a custom ajaxConnector. I'm following the instructions here http://rtfm.modx.com/display/revolution20/Custom+Manager+Pages but it's not seeming to help me at all.

    Here is the code I have:
    require_once ( '../config.core.php' );
    require_once MODX_CORE_PATH . 'config/' . MODX_CONFIG_KEY . '.inc.php';
    require_once MODX_CONNECTORS_PATH . 'index.php';
    $modx->request->handleRequest( array(
        'processors_path'   => $modx->getOption( 'core_path' ) . 'components/mycomponent/processors/',
        'location'          => '',
    ) );
    



    However I have no idea how to actually get that to work.. the only output I receive from that page is

    {"success":false,"message":"Access denied.","total":0,"data":[],"object":[]}

    Further debugging of what's going on reveals the following:

    Undefined index: action (/var/www/core/model/modx/modconnectorrequest.class.php:61)

    I'm wanting to use jQuery to interact with the connector but I just have no idea how I'm supposed to manipulate the data in that file.
      • 4172
      • 5,888 Posts
      if thats for frontend, the simplest way to create ajax-connectors is to create a new resource with blank template and place a snippet-call to that resource, which returns the ajax-responce. Then call the url of that resource by your jquery-ajax-request.
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 39521
        • 15 Posts
        I'm building a custom manager page, so it's in the back-end.
          • 33968
          • 863 Posts
          I'd steer clear of using jQuery in the manager as you already have access to a powerful JS library in MODExt / ExtJS.

          You'd be best checking out the Doodles tutorial (parts 1 & 2) for a walk-through on how to put together a CMP and access data via processors.
            • 4172
            • 5,888 Posts
            what kind of CMP are you planning to build? Perhaps its very easy to to build that one by MIGXdb.
            See http://rtfm.modx.com/display/ADDON/MIGXdb.Create+doodles+manager+with+help+of+MIGXdb
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 18373 ☆ A M B ☆
              • 3,141 Posts
              You need to define an "action" POST or GET (don't think that matters) var which identifies the processor your connector needs to execute. So an action of "dothis" would try to run the processor in processors/dothis(.class).php.

              The access denied message seems to indicate the connector doesn't share your session or you're not logged in..
                Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                • 3548
                • 102 Posts
                Basically, in ajax call (from jquery) you should have action variable, i.e.
                $.ajax({
                  type: "POST or GET", //and theese are not the same, use GET for retrieving, POST for new entries
                  url: "hit/your/connector",
                  data: { action: "path/to/proccessor" }
                })
                

                Regarding access denied, there are two options (quote from docs):
                There's a few reasons for this. One is that the connectors are locked down and don't allow anyone without a MODX manager session to access them. Secondly, all requests to connectors must pass a unique-to-your-site authorization key that prevents CRSF attacks. It can either be passed in the HTTP headers as 'modAuth', or in a REQUEST var as HTTP_MODAUTH. The value will be $modx->siteId, which is set on a new install, and loaded when MODX is loaded.

                Hope it helps, and yes Lucas has good point, you will be doing yourself a favoir going with ExtJs.

                Regards
                  Antonio Zdilar
                  linearvector.com