如何在调用此函数时获取表单的发布数据
$(window).load(function()
使用以下内容获取值但不执行任何操作。
$('#id_state').val();
答案 0 :(得分:1)
如果我没错,这就是你需要的:
<script>
$(window).load(function(){
var id_state=<?php if(isset($_POST["id_state"]){echo $_POST["id_state"];}else{ echo 0;}?>;
});
</script>
答案 1 :(得分:0)
尝试使用ajax
提交表单下面的例子不是一个完美的答案。
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
<form id="formoid" action="studentFormInsert.php" title="" method="post">
<div>
<label class="title">First Name</label>
<input type="text" id="name" name="name" >
</div>
<div>
<label class="title">Name</label>
<input type="text" id="name2" name="name2" >
</div>
<div>
<input type="submit" id="submitButton" name="submitButton" value="Submit">
</div>
</form>
<script type='text/javascript'>
/* attach a submit handler to the form */
$("#formoid").submit(function(event) {
/* stop form from submitting normally */
event.preventDefault();
/* get the action attribute from the <form action=""> element */
var $form = $( this ),
url = $form.attr( 'action' );
/* Send the data using post with element id name and name2*/
var posting = $.post( url, { name: $('#name').val(), name2: $('#name2').val() } );
/* Alerts the results */
posting.done(function( data ) {
alert('success');
});
});
</script>
</body>