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

    Have a weird problem on a MODx site that I have not encountered before.
    I’m using an Ajax call to query stock levels in a cart I built, however I am getting the error below intermittently:

    - Access to restricted URI denied code 1012

    Having googled the below it seems this error is only thrown when you try to make a cross domain Ajax call in JQuery, and i’m not doing this!!
    Page here: http://www.happythreads.co.uk/catalogue/tops/koi_ashley_top.html

    This page has stopped working on 2 occasions. The first time I added the absolute url. This got it going again and I assumed as I had addded a url off the root, the JS was just making a mistake because it could not read the full url. This fix stopped working just recently?!?

    I have sinced added the jsonp:’jsonp_callback’ to my Ajax request, and the absolute url.
    It working again but because this just "stopped" before when it was fine i’m wondering if anyone has seen this before, or knows what going on?

    Thanks in Advance,

    J

    MODx: 0.9.6.3
    IIS Hosting, with ISAPI url rewrite
      • 37550 ☆ A M B ☆
      • 711 Posts
      Hi Justin,

      I seemed to have lost you on the web chat,

      If you try to access one of your URLs without the www prefix you will get the error as it’s being classed as a cross domain Ajax request which is not allowed.

      http://happythreads.co.uk/catalogue/tops/koi_ashley_top.html <- does not allow add to cart
      http://www.happythreads.co.uk/catalogue/tops/koi_ashley_top.html <- works

      What you could either do is use relative paths to call the ajax path or within your domain .htaccess file add the following to the bottom of the file, which will always have the browser switch to www.happythreads.co.uk if a user visits on http://happythreads.co.uk


      RewriteCond %{HTTP:Host} ^happythreads.co.uk$
      RewriteRule (.*) http://www.happythreads.co.uk$1 [NC,R=301]

      Thanks Aaron
        http://www.onesmarthost.co.uk
        UK MODX Hosting with love.
        • 15083
        • 697 Posts
        Hi Aaron,

        I have done this, however with relative urls I had this problem before.
        I am simply referencing the script from the root (as this will/should always work)

        I don’t know how this just stops working. I hate the word intermittent, as much as the next developer smiley

        Thanks for the help...

        J

          • 37550 ☆ A M B ☆
          • 711 Posts
          I think if you force your site to always be www. by applying the .htaccess file rule the problem should go away and you can still continue to use the absolute URL.

          This will also be a good benefit for SEO purposes as well.

          Let me know how you get on.

          Aaron
            http://www.onesmarthost.co.uk
            UK MODX Hosting with love.
            • 15083
            • 697 Posts
            Well I think I might have figured out why it was happening.
            In my templates I had the base url set using the MODx placeholder: [(site_url)]

            On the homepage template this was being drawn out as: http://www.happythreads.co.uk/
            However on the sub pages it was being drawn out as http://happythreads.co.uk/

            Any idea why the www. was being dropped?
            I presume this is just taken from the DB and dropped into the template by the parser?

            I have hardcoded the base url now, and made the Ajax paths relative. I can’t see now how it can see any of my calls as cross domain!!

              • 37550 ☆ A M B ☆
              • 711 Posts
              Hi Justin,

              If I remember right base_url and [(site_url)] are populated when a user visits your site so if they visit on http:// the pages will cache that URL where’s if they visit other pages on http://www it will cache that.

              Flushing the cache will bring the site back to normal and may explain why the problem was intermitant.

              With the changes you have now made it looks like you should be all set, did you also set the ISAPI Rewrite .htaccess file to include this:


              RewriteCond %{HTTP:Host} ^happythreads.co.uk$
              RewriteRule (.*) http://www.happythreads.co.uk$1 [NC,R=301]

              If you do this when a visitor comes to your site on http://happythreads.co.uk/ it will automatically change the address bar URL to: http://www.happythreads.co.uk/

              Aaron
                http://www.onesmarthost.co.uk
                UK MODX Hosting with love.
                • 15083
                • 697 Posts
                Hi Aaron,

                I have simply replaced the [(site_url)] with the full url, and cleared the site cache.
                I don’t understand why it would strip the www. (anyone??)

                I also added the re-write rule as you suggested, so hopefully this is the end of this problem put to bed!

                thanks for your help.

                J

                - This has to be the most plausible explanation for what happened also. User came to site and url got cached as http://happythreads.co.uk. This caused Jquery to throw a tantrum about cross domain posting.