-1

I just finished learning Ajax so I tried to make a simple project(a simple port scanner), it not working for me. I have no idea what is the problem. It's just showing 'Scan started'. please help me. There is no problem inside the php file, only in this code(VVVV)

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>

Thanks, Mr. Frost

4
  • I'm guessing you're trying to scan other domains than your own, and javascript has a same origin policy
    – adeneo
    Aug 8, 2014 at 9:34
  • @adeneo — You can see the URL being requested in the code. It isn't (obviously) a cross origin policy issue.
    – Quentin
    Aug 8, 2014 at 9:34
  • 1
    What have you done to debug this? Look at your browser's JavaScript console. Do you see any errors? Look at your browser's Developer Tools Net tab. Do you see the HTTP requests you are expecting being made? Do you see the responses you are expecting being received?
    – Quentin
    Aug 8, 2014 at 9:35
  • I got a php script who is working. Any way the problem was that I needed to use .value and not .innerHTML
    – Mr. Frost
    Aug 8, 2014 at 10:01

1 Answer 1

1

To read the value from an text input, use the value property, not the innerHTML property.

An input element is defined as being EMPTY, it can't have any child nodes, so innerHTML should always be an empty string.

1
  • It's working! Thank you, I learned new thing bcuz of that :)
    – Mr. Frost
    Aug 8, 2014 at 9:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.