PHP表单无法通过ajax提交访问


php form cannot submit which access by ajax

我尝试在php文件中使用isset($_POST(['submit']))提交表单,通过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>&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</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>&nbsp;</td>
            <td>
&nbsp;<input name="submit" type="submit" value="Save Changes"/></td>
            <td>&nbsp;</td>
            <td style="width: 298px">
            &nbsp;</td>
        </tr>
        <tr>
<td style="width: 244px; height: 26px;"><h5>Effective Width&nbsp;:&nbsp;</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.p php中的表单不能毫无错误地提交。请帮助。由于

这是因为你没有通过post传递任何数据。

<script>
$(document).ready(function() {
$.ajax({
  url: './B.php',
  type: 'POST',
  data: { submit: "submit"},
  success: function(data) 
  { $("#showB").html(data);}
  });
});
</script>

将适当的data传递给$.ajax

https://api.jquery.com/jQuery.ajax/