Has anyone got any ideas what is wrong with the below, my first ever attempt at an ajax script. Maybe it can't be used in this way?
function sitemap()
{
var urls = '
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
link = "";
links = document.anchors.length-1;
for (loop = 0; loop < links; loop++)
{
link = document.anchors[loop].href;
urls += '<url><loc>' + link + '</loc></url>';
}
urls += '</urlset>';
if (window.XMLHttpRequest) // Object of the current windows
{
xhr = new XMLHttpRequest(); // Firefox, Safari, ...
}
else
if (window.ActiveXObject) // ActiveX version
{
xhr = new ActiveXObject("Microsoft.XMLHTTP"); // Internet Explorer
}
var url = "test.php";
var params = "sitemap=" + urls;
xhr.open("POST", url, true);
//Send the proper header information along with the request
xhr.setRequestHeader("Content-type", "application/xml");
xhr.setRequestHeader("Content-length", params.length-1);
xhr.setRequestHeader("Connection", "close");
xhr.send(params);
}