Mub*_*bin 2 html javascript php ajax jquery
我有以下表格,我想发布到page.php,并希望在page.php上获得结果,并希望使用AJAX或JQUERY在表格框中显示数据,这可能吗?如果是,请告诉我.我不想刷新页面,因为我想填充单页上的所有数据,并希望在该页面上显示所有结果(IN表格单元格作为一个表中的用户输入数据,它将更新其响应).
<form method = "post" action = "page.php">
<input type = "text" name = "fld1" id = "fld1" />
<input type = "text" name = "result1" id = "result1" value = "value_from_php_page" disabled />
...
</form>
Run Code Online (Sandbox Code Playgroud)
对的,这是可能的.看看这个例子.
On your page.php
<?php
echo $_POST["fld1"];
?>
Run Code Online (Sandbox Code Playgroud)
On your myForm.html. event.preventDefault() is needed, otherwise submit will perform at default and page will be reload.
<script>
$(function(){
$("#submit").click(function(event){
event.preventDefault();
$.ajax({
type:"post",
url:"page.php"
data:$("#form").serialize(),
success:function(response){
alert(response);
}
});
});
});
</script>
<form id="form" method = "post" action = "page.php">
<input type = "text" name = "fld1" id = "fld1" />
<input type = "text" name = "result1" id = "result1" value = "value_from_php_page" disabled />
<input type="submit" value="Submit" id="submit">
</form>
Run Code Online (Sandbox Code Playgroud)