1

I would like to access an HTML file (makemeastring.html) from JavaScript as a String. jQuery's .load does not seem to work.

1
  • What error throws jQuery.load(...)? Commented Feb 7, 2015 at 22:17

1 Answer 1

3
$.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.

http://api.jquery.com/jquery.get/

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

6 Comments

Thanks! When I try to run this in chrome I always get the .fail thing though.
@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.
" XMLHttpRequest cannot load blahblahfilepath/makemeastring.html. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource."
makemeastring.html is on the same level as the javascript file
@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.
|

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.