We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 54325
    • 22 Posts
    Hi,
    What I did:
    - create new ACL
    - create (mirror) all resources required by new template
    - created new template
    - copied existing template's code to new template - ALL INLINE JS FOR TEMPLATE NOT CHANGED
    - pointed all new resources at new template
    - pointed all new resources to new resource group
    - added a user (me) to the new resource group and logged in as that user
    - at the suggestion someone on these forums, I added <base href="https://abc.com/"/> to the head section of the NEW template
    .... at this point I can see the new resources and am using the new template

    Issue: ANY inline JS (jquery) $.post(...) present in the copied template fails with 404. Original template's $.post calls work as expected. $.post's look like:


    $.post('MODX_AJAX_RESOURCE', params, function(msg){
    var result = JSON.parse(msg);

    if (result.error != undefined){
    alert('error');
    } else {
    window.location.reload();
    }
    }).fail(function(XMLHttpRequest, textStatus, errorThrown){alert('failed save');
    });
    });
    The "fail"'s args are set to:

    XMLHttpRequest.status: 404
    textStatus: "error"
    errorThrown: "Not Found"




    • Original template ajax calls work AS EXPECTED.
    • AJAX resource was not changed.
    • Snippet endpoints were not changed.
    • The fully-qualified path looks valid.

    What needs to happen for the new template's inline JS calls to see the existing ajax resource/snippet endpoints?


    Please help, I do not what else to look for.

    James [ed. note: jxarms3 last edited this post 5 years, 8 months ago.]
      • 3749
      • 24,544 Posts
      Is it possible that you're not logged in in the front end when the Ajax call is made? In that case, if the Ajax resource is protected, you would get a 404 since you don't have permission to access it.

      If removing the Ajax resource from all resource groups and clearing the cache solves your problem, it's a MODX permission problem.

        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 54325
        • 22 Posts
        Quote from: BobRay at Aug 22, 2018, 02:42 AM
        Is it possible that you're not logged in in the front end when the Ajax call is made? In that case, if the Ajax resource is protected, you would get a 404 since you don't have permission to access it.

        If removing the Ajax resource from all resource groups and clearing the cache solves your problem, it's a MODX permission problem.


        I don't understand what you mean by "not logged into the front end when the AJAX call is made". I am logged in??? Anyway:

        I unchecked the the resource groups from the MODX resource: ajax-actions.html and cleared the cache. The $.post completed successfully. I reset all the resource groups on the MODX resource and the same issue occurred. Seems like this is a MODX permission issue. What is the prescribed method of correcting the permission's issue?

        Thanks again for your help!!!
          • 3749
          • 24,544 Posts
          If you're viewing the site while logged in to the Manager, you're not logged in to the front end ('web' context) unless you explicitly log in there.

          One solution is to leave the resource unprotected and send some authorization code in the Ajax call. Then check for the authorization code in the PHP that processes the Ajax call.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting