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

    I had a lot of troubles getting AJAX working on my local server, but at least it works now (with one small flaw). As I use a lost of external scripts, I created a configuration parameter for my module called : $modpath

    $basepath = $modx->config["base_path"];
    $modpath = isset($modpath) ? $basepath.$modpath : $basepath.'assets/modules/mymodule';


    As i’m using the WinXP distribution of uniserver to develop my application, $modpath now has the value : "W:/www/assets/modules/mymodule".



    This is fine for PHP, but if I use it this way :

    <script type="text/javascript">
    var modpath = '<?php echo $modpath; ?>';
    </script>


    so that in my AJAX code I can call my handlers that way :

    /********************************************** HERE  ***************/
    		var url = modpath + '/ajax.handler.php';
    /********************************************************************/
    		var params = 'catname=' + $F('txtNewCategory');
    		alert(url);
    		var request = new Ajax.Request(
    			url,
    			{
    				method: 'get',
    				parameters: params,
    				asynchronous:true,
    				onComplete: function(r) {
    					alert(r.responseText);
    				}
    			});
    	}


    it try to call the url "W:/www/assets/modules/mymodule" that cannot exist. how could I set a base url easily for my scripts??

    thanks a lot in advance,

    Blaise
      Blaise Bernier

      www.medialdesign.com - Solutions for small business, hosting, design and more!
      • 11413
      • 203 Posts
      Found an easy way : added a &mod_url to my module’s configuration!
        Blaise Bernier

        www.medialdesign.com - Solutions for small business, hosting, design and more!
      • I started my module by basically ripping off the QuickEdit module’s code and editing it for my own purposes. I figure it’ll be a long time before I ever come close to Adam’s coding ability!
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
        • grunt_lord, there is also $modx->config[’base_url’] and $modx->config[’site_url’] to use when building URL’s -- $modx->config[’base_path’] is more commonly used to include files or other situations where a full file system path is required.
            • 11413
            • 203 Posts
            I think there was a page on the website listing all the configuration variables, but I’m unable to find it again... anyway, thanks, it’s gonna make it easier to configure than having to enter it by hand smiley

            bye,

            Blaise
              Blaise Bernier

              www.medialdesign.com - Solutions for small business, hosting, design and more!
            • Quote from: grunt_lord at Mar 09, 2006, 02:02 AM

              I think there was a page on the website listing all the configuration variables, but I’m unable to find it again... anyway, thanks, it’s gonna make it easier to configure than having to enter it by hand smiley
              Probably thinking of http://modxcms.com/modx-tags.html. Look at the Settings tags. This is basically a list of the configuration variables available in the $modx->config array.
              wink
                • 11413
                • 203 Posts
                that was it... I think smiley

                thanks!
                  Blaise Bernier

                  www.medialdesign.com - Solutions for small business, hosting, design and more!