I opened Firefox's scratchpad and entered...
function ajaxRequest()
{
var xmlhttp;
var domainName = location.host;
var url = 'http://leke.dyndns.org/cgi/dn2ipa/resolve-dns.py?domainName=';
url = url + domainName + '&x=' + Math.random(); // x= to avoid browser caching;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
alert(domainName+'='+xmlhttp.responseText);
}
}
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
ajaxRequest();
How come my ajax code works in the same domain as the remote script (http://leke.dyndns.org), but not in other domains (like http://stackoverflow.com)?
If it helps, here is the cgi side...
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import os, cgi, cgitb, socket
cgitb.enable()
cgiData = cgi.FieldStorage() # Domain Name
domainName = cgiData.getvalue('domainName')
ipa = socket.gethostbyaddr(domainName)
sendIpa = ipa[2][0]
print 'Content-Type: text/html;charset=utf-8'
print ""
print sendIpa