javascript - XMLHttpRequest returning a status of 0 -



javascript - XMLHttpRequest returning a status of 0 -

when function run, request.status = 0. means network downwards since webpage loaded, cannot possible. think may because using xampp , running on localhost not sure how prepare problem.

here javascript function:

<script type="text/javascript"> function submitform() { var userkey; var username = login_form.elements["username"].value; function getkey() { var request = new xmlhttprequest(); request.onreadystatechange = function() { if(request.readystate == 4 && request.status == 200){ userkey = request.responsetext; } } request.open("post", "key.php", true); request.setrequestheader('content-type', 'application/x-www-form-urlencoded'); request.send("username="+username); } getkey(); } </script>

here php function called "key.php". in same folder html file:

<?php if (array_key_exists('username', $_post)) { $username = $_post['username']; echo '<script language="javascript">'; echo 'alert("message sent")'; echo '</script>'; } else { echo 'invalid parameters!'; } ?>

javascript php html xmlhttprequest xampp

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -