I would like to access an HTML file (makemeastring.html) from JavaScript as a String. jQuery's .load does not seem to work.
1 Answer
$.get('makemeastring.html').then(function (data) {
console.log(data);
}).fail(function () {
// Error occurred, handle it here
});
jQuery's .load() function puts data into a DOM element. You don't want that, so .get() will be fine.
6 Comments
Bryan Tan
Thanks! When I try to run this in chrome I always get the .fail thing though.
Brad
@BryanTan Then something is wrong. Not sure how to help you since you're the only one that can see your JavaScript console with errors, and network tab with possible errors on network requests. You'll need to tell us what the error is.
Bryan Tan
" XMLHttpRequest cannot load blahblahfilepath/makemeastring.html. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource."
Bryan Tan
makemeastring.html is on the same level as the javascript file
Brad
@BryanTan Then, why are you trying to make a cross-origin request? You are running this on a web server, right? AJAX doesn't work when there isn't a server to connect to.
|
jQuery.load(...)?