function post()
{
var cvs = $('#client-nbr').val();
var cs = $('#cs').val();
$.post('http://sitea.com/a.php',{postcvs:cvs,postch1:cs});
return false;
}
调用函数onsubmit:
<form action="http://siteb.com/b.php" method="post" id="formID" onsubmit="post()">
<input type="text" name="client-nbr" id="client-nbr" /> <br>
<input type="text" name="cs" id="cs" /> <br>
<button type="submit" name="submit" id="submit">subscribe</button>
</form>
我想等
function post()
完成发布后再提交默认操作吗? 最佳答案
<form action="http://siteb.com/b.php" method="post" id="formID">
<input type="text" name="client-nbr" id="client-nbr" /> <br>
<input type="text" name="cs" id="cs" /> <br>
<!-- http://stackoverflow.com/a/23968244/2240375 -->
<button type="submit" name="submit_btn" id="submit_btn">subscribe</button>
</form>
<script>
$("#formID").submit(function (objEvent) {
// Prevent your form submition
objEvent.preventDefault();
$.ajax({
type: 'POST',
url: "http://sitea.com/a.php",
data: {
postcvs: $('#client-nbr').val(),
postch1: $('#cs').val()
},
success: function (strResponseData) {
// After successfull ajax request submit the form
$("#formID")[0].submit();
}
});
})
</script>