Skip to content

Instantly share code, notes, and snippets.

@eas604
Created October 6, 2014 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save eas604/b86a70fd36b267506aa1 to your computer and use it in GitHub Desktop.
Save eas604/b86a70fd36b267506aa1 to your computer and use it in GitHub Desktop.
Simple async view loader in jQuery. Gets the target URL, then puts the output HTML in the target div.
function loadView(url, div) {
// Will get the result of the appropriate view url then display the data
// in the specified `div`, where `div` is a jQuery selector. Usage:
// var div = $("#my_target_div");
// var url = "~/Example/View";
// loadView(url, div);
$.get(url, function (data) { div.html(data); }, "html");
// Parameter dataType value "html" required on Firefox only, for some reason.
// See http://stackoverflow.com/questions/11441020/jquery-ajax-exception-only-in-firefox-node-cannot-be-inserted-at-the-specified
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment