0
var templateLink = envVars.rootTemplateFolder + $(this).attr('link');
console.log("templateLink : ", templateLink);

    $.ajax({
        method: "GET",
        url: templateLink,
        context: this,
        success : function(result){
            var theHtml = result.toString();
                $(this).replaceWith(theHtml);
            }

templateLink should = "resources/spa/templates/header.html" and according to the console log it is.

BUT I am always getting a 404 on "resources/spa/resources/spa/templates/header.html"

I can take out the variable and just pass the basic string "resources/spa/templates/header.html" And, I still get the duplicate.

If just leave it as "/templates/header.html", then it will not repeat the "resources/spa", of course, the rest of the string is not there now. So this indicates that the object being passed to the AJAX call is getting parsed and changed.

How to I stop this? I'm confused as to why it is acting this way.

Any ideas?

1 Answer 1

1

It's not getting parsed or changed. The problem is that you aren't considering the path that ajax gets it's added to the path location you're in. So if you're at http://yoursite/resources/spa/templates/header.html and your alias in Apache for example is http://yoursite/resources/spa/ the base path is added to your ajax string. This is probably the problem.

The the actual path your browser is, and remove the common parts.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the quick reply! That lead me on the right path. I do understand it's not the AJAX call now. The relative path, should add the common parts, like you say. But it won't access the files. Why is it being choosy on when it applies the resources/spa versus when it doesn't? If I add even another small string "a" instead of "resources/spa", then it adds the relative path "resources/sap, but if I don't add "a", then it doesn't add anything.
You have to consider what page are you sending the ajax request. The best would be to send a complete url not a relative path. Sent it like: 'yoursite/resources/spa/templates/header.html' instead of 'resources/spa/templates/header.html ' and you should be fine.
correcting: Sent it like: http://yoursite/resources/spa/templates/header.html instead of resources/spa/templates/header.html.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.