Reputation: 1
function loadAjax(filename){
var ajax;
if(window.XMLHttpRequest){
ajax=new XMLHttpRequest();
}
ajax.onreadystatechange=function(){
if(ajax.readyState==4 && ajax.status==200){
document.getElementById("target").innerHTML = ajax.responseText;
}
}
ajax.open("GET",filename,true);
ajax.send();
}
If filename
is a .txt
file, this works as expected. However, if it is a .html
file, no response is shown.
Upvotes: 0
Views: 77
Reputation: 30310
The answer is of course yes, but I would suggest using JQuery's load
function as described here. It is just so much easier to use an abstraction rather than mess with the low-level details of the XHR and the DOM.
This assumes your HTML is valid.
In your case, the code would be something like $("#target").load(filename);
Upvotes: 4
Reputation: 20418
Yes its Possible Use JQuery load
Script
<script type="text/javascript">
$(document).ready(function(){
$("#urButton").click(function() {
$("#urDiv").load("trackingCode.html");
});
});
</script>
HTML
<button id="urButton">Click Me</button>
<div id="urDiv"></div>
Upvotes: 1