In JavaScript, is there a way to get the source code of a given URL?

advertisements

In JavaScript, is there a way to get source code of a page given its URL? Kind of equivalent to PHP's file_get_contents()


You can just download from a URL through XMLHttpRequest (or jQuery's ajax):

$.get(
    'yourfile.js',
    function(data) {
        // The source code is in data
    }
);