php表单无法通过ajax提交哪些访问权限

时间:2014-05-07 02:36:57

标签: php

我尝试使用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>&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.php中的表单无法提交且没有错误。请帮忙。感谢

1 个答案:

答案 0 :(得分:0)

因为你没有通过帖子传递任何数据。

<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/