javascript - How do i submit a hidden form using ajax when the page loads? -
how can submit hidden form php using ajax when page loads?
i have form 1 hidden value want submit without refreshing page or response message server. how can implement in ajax? form. have form in same page.
<form id = "id_form" action = "validate.php" method = "post"> <input type = "hidden" name = "task_id" id = "task_id" value = <?php echo $_get['task_id'];?>> </form>
similar zafar's answer using jquery
actually 1 of examples on jquery site https://api.jquery.com/jquery.post/
$(document).ready(function() { $.post("validate.php", $("#id_form").serialize()); });
you can .done(), .fail(), , .always() if want response said did not want.
in pure javascript
body.onload = function() { var xmlhttp = new xmlhttprequest(); xmlhttp.open("post","validate.php",true); xmlhttp.setrequestheader("content-type","application/x-www-form-urlencoded"); xmlhttp.send("task_id=" + document.getelementbyid("task_id").value); };
Comments
Post a Comment