我尝试使用isset($ _ POST([' submit']))在php文件中提交表单,该文件通过ajax访问但它不起作用。请在下面找到代码段:
<html>
<script>
$(document).ready(function() {
$.ajax({
url: './B.php',
type: 'POST',
success: function(data)
{ $("#showB").html(data);}
});
});
</script>
<body>
<table style="width: 100%">
<tr>
<td colspan="2"><div id="showB"></div></td>
</tr>
</table>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</body>
</html>
B.php:
<html>
<?php
if(isset($_POST['submit']) && !empty($_POST['submit'])) {
$message= "halo";
}
?>
<head>
<title>Untitled 1</title>
</head>
<body>
<table>
<tr>
<td style="height: 30px"></td>
<td style="height: 30px"><?php if(!empty($message)) { echo $message; } ?></td>
<td style="height: 30px"></td>
<td style="height: 30px; width: 298px;"></td>
</tr>
<form method="post" action="halo.php">
<tr>
<td> </td>
<td>
<input name="submit" type="submit" value="Save Changes"/></td>
<td> </td>
<td style="width: 298px">
</td>
</tr>
<tr>
<td style="width: 244px; height: 26px;"><h5>Effective Width : </h5></td>
<td style="width: 262px; height: 26px;"><input name="effectivewidth" type="text"/></td>
<td style="width: 261px; height: 26px;"></td>
<td style="width: 298px; height: 26px;"></td>
</tr>
</form>
</table>
</body>
</html>
B.php中的表单无法提交且没有错误。请帮忙。感谢
答案 0 :(得分:0)
因为你没有通过帖子传递任何数据。
<script>
$(document).ready(function() {
$.ajax({
url: './B.php',
type: 'POST',
data: { submit: "submit"},
success: function(data)
{ $("#showB").html(data);}
});
});
</script>
将相应的data
传递给$.ajax