when using ajax, will this code bring up javascript content?
var xmlhttp;
var nocache = 0;
function further($id)
{
xmlhttp=getXmlHttpObject();
if (xmlhttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="further.php?Pid=" + $id;
//url=url+"cachestopper=" + Math.random();
xmlhttp.onreadystatechange=handleAjaxResponse;
xmlhttp.open("GET",url,'&nocache = '+nocache,true);
xmlhttp.send(null);
}
function handleAjaxResponse()
{
if (xmlhttp.readyState==4)
{
document.getElementById("output").innerHTML = xmlhttp.responseText;
}else{
document.getElementById("main").innerHTML = "";
}
}
function getXmlHttpObject()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
I know this works well for html and text content, but in my case, I need to produce a diagram that is generated using javascript, d3.js to be exact. Will .innerHTML = xmlhttp.responseText; work for this? If not, what will I have to use instead to produce the javascript content?
A small bug in your code while opening a XMLHttpRequest Object.
Try this http://jsfiddle.net/nubgw/7/