samedi 25 avril 2015

AJAX not working when pressing submit button


Im practicing the basics of AJAX.

When I click Submit nothing happens.

Here’s my code.

<!doctype html>
<html>

<head>
<meta charset="utf-8">
<title>FIRST AJAX!</title>

<script>
function alertMe(){
    var field1 = document.getElementById("Field1").value;
    var parser = "parse.php";
    var values = "name="+filed1;
    var xml = new XMLHttpRequest();
    xml.open("POST", parser, true);
    xml.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xml.onreadystatechange = function(){
        if(xml.readyState == 4 && xml.status == 200){
            document.getElementById('output').innerHTML = xml.responseText;
        }
    }
    xml.send(values);
    document.getElementById('output').innerHTML = " Loading ... ";
}
</script>
</head>

<body>
    <input type="text" name="Field1" id="Field1"/>
    <input type="submit" name="Fsend" onClick="alertMe();"/>
    <p id="output"></p>
</body>

</html>

Thank you.


Aucun commentaire:

Enregistrer un commentaire