After completing my learning on Ajax, I decided to work on a simple project - a port scanner. However, I am facing issues with it as it is not working properly. The only message that pops up is 'Scan started' and I can't figure out what the problem is. The issue seems to be within this code (VVVV). Can someone please assist me?
var ports = [80, 22, 443, 21, 8080, 25, 3306];
function loadData(url, port){
var xmlhttp;
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)
{
document.getElementById("myDiv").innerHTML += "<br>" + xmlhttp.responseText;
}
}
xmlhttp.open("GET","scan.php?url=" + url + "&port=" + port,true);
xmlhttp.send();
}
function scan () {
// body...
document.getElementById("myDiv").innerHTML = "Scan Started";
if(document.getElementById("url").innerHTML){
var url = document.getElementById("url").innerHTML;
for (var i = 0; i < ports.length; i++) {
loadData(url, ports[i]);
};
}
}
</script>
<center>
<input type="text" id="url" name="url"><br><button onclick="scan()">Scan</button>
<br>
<div id="myDiv"></div>
Your assistance is much appreciated.