Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

APIs

Use Ajax on local file

I have a file named homepage.js which contain an Ajax request and append info to the page. I have a main.js file and here I want to create an Ajax request to the homepage.js. Is it possible? My local path (of homepage.js) starts with file:// and it looks like its not valid. Any solution for this? $( document ).ready(function() {

$.ajax({
    url: 'file:///Users/shiralotan/Desktop/Project%20BTC/homepage.js',

    success: function(resualt){
        $("#coinsDiv").html(resualt)
    }
})

})

1 Answer

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 Points

Can you share the rest of the code for the project, either on GitHub or a Treehouse workspace snapshot? FYI, it's good practice to develop your website by serving up your with a local development server like http-server rather than viewing them in the file system (file://).

What's the goal here? What is in homepage.js that you want to fetch with an AJAX request? Could you just load the script for homepage.js along with the other scripts at the beginning when the page loads?