javascript - AJAX not working when pressing submit button -
i practicing basics of ajax.
when click submit nothing happens.
here’s 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.
the problem declaring variable called field1, , calling filed1.
try checking console errors, it's useful
Comments
Post a Comment