Skip to content

Instantly share code, notes, and snippets.

@elrrrrrrr
Created August 18, 2014 07:30
Show Gist options
  • Save elrrrrrrr/24969178d587a372b7d0 to your computer and use it in GitHub Desktop.
Save elrrrrrrr/24969178d587a372b7d0 to your computer and use it in GitHub Desktop.
异步加载模版
function loadDialog(name, oncomplete) {
var xhr = new XMLHttpRequest();
xhr.open("get", "/js/dialog/" + name, true);
xhr.onreadystatechange = function(){
if (xhr.readyState == 4 && xhr.status == 200){
var div = document.getElementById("dlg-holder");
div.innerHTML = xhr.responseText;
oncomplete();
} else {
//处理异常
}
};
xhr.send(null);
}
@elrrrrrrr
Copy link
Author

// in Jquery
function loadTemplate(name, oncomplete){
$('#id').load("js/templte"+ name, oncomplete)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment