I am using ajax call to a remote server which is supposed to return a javascript block in response . My ajax call is something like :
var m3_u = (location.protocol=='https:'?'https://ads.admarvel.com/fam/javascriptGetAd.php':'http://ads.admarvel.com/fam/javascriptGetAd.php');
var m3_r = Math.floor(Math.random()*99999999999);
var queryString = '?partner_id='+partnerId;
queryString += '&site_id='+siteId;
queryString += '&target_params=' + targetparams_str;
queryString += '&version=1.5';
queryString += '&language=javascript';
queryString += '&format=wap';
queryString += '&cb='+m3_r;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
alert(xmlhttp);
xmlhttp.onreadystatechange=function()
{
alert(xmlhttp.readyState);
if (xmlhttp.readyState==4)
{
alert("response "+xmlhttp.responseXML);
console.log(xmlhttp.responseXML);
//document.getElementById('ad').innerHTML = xmlhttp.responseText;
//document.write("<scr"+"ipt type='text/javascript'>");
//document.write(xmlhttp.responseText);
//document.write("<\/scr"+"ipt>");
}
}
xmlhttp.open("GET",m3_u+queryString,false);
xmlhttp.setRequestHeader('Content-Type','text/javascript');
xmlhttp.send();
But the response that I am getting is null . When I hit the url in the broser , it properly returns me a javascript code block .
What is the right way to do this?
Content-Typeas a request header if you're using GET.