We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4619
    • 23 Posts
    I use ajax request with

    $.getJSON('index.php',params,function(data) { ..... });


    with
    var params={
    		id: id,
    		pm:pm
    	};


    But unfortunately with Friendly url, the parameter pm is lost with the url rewriting:

    # The Friendly URLs part
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

    The GET request www.domain.com/index.php?id=id&pm=pm send through ajax is rewritted in www.domain.com/alias.html but the pm parameter is lost !!!!

    How could I use an extra parameter with FURL activated ?
    Does it possible to inhibit the url rewriting for a specific MODx document (the ajax Handler document) ?

    Thanks for your help
      • 9207 ☆ A M B ☆
      • 2,475 Posts
      Good question. Can you reference the url of the target? Maybe something like this:

      $.getJSON('index.php?id=123',params,function(data) { ..... });


      or maybe this?

      $.getJSON('/furl/to/page',params,function(data) { ..... });
        • 4619
        • 23 Posts
        $.getJSON('index.php?id=123',params,function(data) { ..... });
        doesn't change anything. The url index.php?id=123&pn=xxx is rewritted as furl_alias.html and pn parameter is lost.

        $.getJSON('/furl/to/page',params,function(data) { ..... });
        provide the correct result but this implies that the js script know if furl are activated or not (if not it should use index.php rather than the furl alias.

        I don't understand why MODx doesn't replace:

        index.php?id=123&someparameters=params

        by:

        furl_alias.ext?someparameters=params
          • 22303 MODX Staff
          • 10,725 Posts
          If you use the proper tags to generate the URLs, it will generate it as the proper FURL in the first place and no rewriting is required. It's not good to reference resources by a non-FURL when FURLs are enabled.
            • 4619
            • 23 Posts
            Quote from: opengeek at Dec 27, 2011, 08:49 AM
            If you use the proper tags to generate the URLs, it will generate it as the proper FURL in the first place and no rewriting is required. It's not good to reference resources by a non-FURL when FURLs are enabled.
            What are you thinking when you say "if you use the proper tags to generate the URLs , it will generate it as the proper FURL in the first place and no rewriting is required" .
            I don't understand you. [ed. note: cariboo last edited this post 14 years, 10 months ago.]
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              In PHP code, use the makeUrl() API function instead of hard-coding the URL.

              http://rtfm.modx.com/display/revolution20/modX.makeUrl

              In an AJAX request, use
               [[~123]]
              [ed. note: sottwell last edited this post 14 years, 10 months ago.]
                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
                • 9207 ☆ A M B ☆
                • 2,475 Posts
                I think the OP was asking how to reference the page URL in Javascript.
                  • 4619
                  • 23 Posts
                  As I am in a javascript file I can't use makeUrl() API. In fact I get from the php code the id of the ajax handler to call:
                  For instance the parameter &ajaxId is used with &ajaxId=`126`
                  Then in the javascript file I call the ajax handler document with:
                  $.getJSON('index.php?',params,function(data) { ..... });


                  Where params is a classical jquery map of parameters with:
                  var params={
                          id: id,
                          other-param:pm
                      };


                  and id = 126

                  Without FURL activated, all is ok, the ajax document handler is correctly call and all the parameters are received.

                  But with FURL, the ajax document handler name is transformed as furl-alias.html and the parameter other-param is definitively lost.
                  I don't know how I should set up a proper URL (which tags I need to use huh) to not loose the parameters.
                    • 4172
                    • 5,888 Posts
                    var params={
                            id: id,
                            pm:pm
                        };


                    where do you get this vars from? where are they defined?

                    If you have your javascript, which defines the vars on your template you can modx let generate the proper url with

                    var ajaxurl='[[~yourajaxid]]';


                    and use it in your script with:

                    $.getJSON(ajaxurl,params,function(data) { ..... });









                      -------------------------------

                      you can buy me a beer, if you like MIGX

                      http://webcmsolutions.de/migx.html

                      Thanks!
                      • 22303 MODX Staff
                      • 10,725 Posts
                      Include your js objects and functions from the external scripts and then instantiate/call them while setting the value of your AJAX endpoint from the generated MODX source. Then you can use makeUrl() or the appropriate link tags.

                      Otherwise, you'll have to hardcode the URI of your AJAX endpoint in the JS. Do not use index.php?id=x if you are using friendly_urls.