使用html模板将数据传递到php文件

使用html模板将数据传递到php文件,php,jquery,html,ajax,Php,Jquery,Html,Ajax,如何使用ajax调用时尝试传递的数据加载table.php文件。我正在使用jquery.load方法尝试第二个参数是数据数组,但不起作用 这是我必须做的一个基本例子,我得到了这个错误 Notice: Undefined variable: field in C:\xampp\htdocs\prueba2\table.php on line 2 index.php <?php $datos = array(array('nombre1','apellidos1'),array('

如何使用ajax调用时尝试传递的数据加载table.php文件。我正在使用jquery.load方法尝试第二个参数是数据数组,但不起作用

这是我必须做的一个基本例子,我得到了这个错误

Notice: Undefined variable: field in C:\xampp\htdocs\prueba2\table.php on line 2
index.php

<?php
    $datos =  array(array('nombre1','apellidos1'),array('nombre2','apellidos2'));
?>
<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
        <h2>Tabla</h2>
        <div id="tabla">
            <table border="1px">
            <?php
                foreach ($datos as $dato) {
                    echo "<tr><td>".$dato[0]."</td><td>".$dato[1]."</td></tr>";
                }
            ?>
            </table>
        </div>

        <form id="search-form" method="POST">
            <input type="text" id="search" name='search'>
            <input type="submit" value="Buscar">
        </form>
        <script
              src="https://code.jquery.com/jquery-1.12.4.min.js"
              integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ="
              crossorigin="anonymous"></script>
        <script type="text/javascript" src="submit.js" ></script>
</body>
</html>
table.php

<div id="tabla">
    <?=$field?>
    <table border="1px">
        <tr>
            <td>a</td><td>b</td>
        </tr>
</table>

ab

变量
$field
表.php中不存在。您需要使用
$\u POST['field']
$\u GET['field']
来代替。

在$\u POST['field']中起作用……但我认为GET是jqueryGET上ajax调用的默认方法,对于
load()
,jqueryGET是默认的,除非您使用对象调用它-对象作为POST发送。From:如果数据作为对象提供,则使用POST方法;否则,假定为GET。
<div id="tabla">
    <?=$field?>
    <table border="1px">
        <tr>
            <td>a</td><td>b</td>
        </tr>
</table>