We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31410
    • 66 Posts
    hello

    i was trying to send a form from frontend with mootools ajax
    from the docs i understood i have to use connectors for ajax requests
    but url i have to give in the javascript
    i have created connectors.php like in myassets components directory
    require_once dirname(dirname(dirname(dirname(dirname(__FILE__))))).’/config.core.php’;
    require_once MODX_CORE_PATH.’config/’.MODX_CONFIG_KEY.’.inc.php’;
    require_once MODX_CONNECTORS_PATH.’index.php’;

    require_once MODX_BASE_PATH.’trunk/core/components/mycomponent/model/component.class.php’;
    $modx->mycompo= new Mycompo($modx);

    if (isset($_REQUEST[’resource’])) {
    $modx->resource = $modx->getObject(’modResource’,$_REQUEST[’resource’]);
    }

    /* handle request */
    $path = $modx->getOption(’processors_path’,$modx->comments->config,$modx->getOption(’base_path’).’trunk/core/components/mycomponent/processors/’);
    $modx->request->handleRequest(array(
    ’processors_path’ => $path,
    ’location’ => ’’,
    ));

    but my actual script is in processors directory
    my example js code look like this
    var myRequest = new Request({url: ’http://localhost/some_url/processors/create.php’}).send(’......’);
    i am confused about this
    so what URL i have to give in the javascript url?

    please help me here

    thanks
    venu

      • 28215
      • 4,149 Posts
      According to your code, the URL should be wherever you put that connector file.

      Then you’ll pass an ’action’ request variable, which will then point to the correct processor. IOW, a processor at processors/item/create would be an action of ’item/create’.
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 31410
        • 66 Posts
        thanks for the reply

        iam not sure if i understood correctly or not

        i have given action as web/create in the jscode

        code is here
        var jsonRequest = new Request.JSON({url: "trunk/assets/components/mycomponent/connector.php", onSuccess: function(responce){
        alert(responce);
        }}).get({’action’: ’web/create’});

        the request is forwarded to connector like this
        http://localhost/modx/trunk/assets/components/mycomponent/connector.php?action=web%2Fcreate

        in the connector i have given like this
        $path = $modx->getOption(’processors_path’,$modx->mycompo->config,$modx->getOption(’base_path’).’trunk/core/components/mycomponent/processors/’);
        $modx->request->handleRequest(array(
        ’processors_path’ => $path,
        ’location’ => ’’,
        ));

        iam not sure how this will redirect to the trunk/core/components/mycomponent/processors/web/create.php

        iam not getting any response from the create.php not sure does the ajax request is forwarded to create.php or not

        let me know did i made any mistake here?

        Thanks

          • 21257 MODX Staff
          • 730 Posts
          Is the root URL of your site actually
          http://localhost/modx/trunk/
          ?
            Mike Schell
            Lead Developer, MODX Cloud
            Email: [email protected]
            GitHub: https://github.com/netProphET/
            Twitter: @mkschell
            • 31410
            • 66 Posts
            base_url is localhost/modx
            the trunk is new component folder where iam working on modx component
              • 31410
              • 66 Posts
              any suggestions please? re: the ajax request
                • 30491
                • 44 Posts
                Im also interested in the same.
                  • 22303 MODX Staff
                  • 10,725 Posts
                  If this is front-end, IMO, you could just use a Resource with a Snippet on it to handle AJAX requests/responses; much, much simpler and more elegant from my perspective. Connectors were intended for back-end functionality to be exposed across Contexts (i.e. for things like front-end editing components to make use of). Creating a new Connector for each component that has AJAX functionality exposed is not the proper approach. But again, this is just my opinion and YMMV.
                    • 31410
                    • 66 Posts
                    Quote from: tourshi at Apr 28, 2010, 08:04 AM

                    Im also interested in the same.
                    are you able to run ajax with mootools
                    i was able to

                    just give connector url from the snippet or class or request as i did in the web request class
                    $this->modx->regClientStartupHTMLBlock(’<script type="text/javascript">
                    var connector_url="’.$this->comments->config[’connector_url’].’";
                    </script>’);

                    in the form i have given action as hidden field and posted along with form like
                    <input type="hidden" name="action" value="place where ur processor file is (i have given action/create)">
                    if you just want to use ajax without forms or any then you can use request.send(action=’web/create’); below


                    var request=new Request({
                    url: connector_url,
                    method:’post’,
                    data: $(’the div form’),
                    onSuccess: function(responce) {
                    if(responce==’success’){
                    alert(responce);
                    }
                    }
                    });
                    request.send();

                    i hope this will be helpful for you
                    i am working on complete tutorial on ajax next week and update you here

                    thanks
                    venu
                      • 14349
                      • 44 Posts
                      Is there running documentation on using Ajax with Revo ? Is similar to doing it with Evo (Evo has an Ajax wiki)

                      If there isn’t i’ll maintain my patience : )