javascript - Ajax POST request does not work -


i don't know doing wrong, looks good. working on localhost , having trouble trying load file.

this code. working in netbeans , console clear without errors.

<!doctype html> <html> <head> <script> function loadxmldoc() {     var xmlhttp;     if (window.xmlhttprequest) { // code ie7+, firefox, chrome, opera, safari         xmlhttp = new xmlhttprequest();     } else { // code ie6, ie5         xmlhttp = new activexobject("microsoft.xmlhttp");     }     xmlhttp.onreadystatechange = function () {         if (xmlhttp.readystate == 4 && xmlhttp.status == 200) {             document.getelementbyid("mydiv").innerhtml = xmlhttp.responsetext;         }     }     xmlhttp.open("post", "demo_post.php", true);     xmlhttp.send(); } </script> </head> <body>  <h2>ajax</h2> <button type="button" onclick="loadxmldoc()">request data</button> <div id="mydiv"></div>  </body> </html> 

when execute code, no results.

in between .open() , .send() invocations, set request header so:

xmlhttp.open("post", "demo_post.php", true); xmlhttp.setrequestheader("content-type","application/x-www-form-urlencoded"); xmlhttp.send(); 

at least, that's how you'd if didn't want use jquery.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -