Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在加载的文件中加载表单结果_Php_Jquery_Html_Ajax - Fatal编程技术网

Php 在加载的文件中加载表单结果

Php 在加载的文件中加载表单结果,php,jquery,html,ajax,Php,Jquery,Html,Ajax,早上好。我正在尝试将来自表单POST的响应加载到同一个文件中 这是我的索引: <div class="right-half"> <div id="include"> </div> </div> <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script> <script type="text/

早上好。我正在尝试将来自表单POST的响应加载到同一个文件中

这是我的索引:

<div class="right-half">
    <div id="include">
</div>
</div>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript"> 
        $("#search").click(function(){
            $("#include").load("admin_search.php"); 
        });
        $("#add").click(function(){
            $("#include").load("include/test.html"); 
        });
        $('#user').submit(function() { // catch the form's submit event
            $.ajax({ // create an AJAX call...
                data: $(this).serialize(), // get the form data
                type: $(this).attr('POST'), // GET or POST
                url: $(this).attr('admin_user.php'), // the file to call
                success: function(response) { // on success..
                    $('#include').html(response); // update the DIV
                }
                });
            return false; // cancel original event to prevent form submitting
        });
</script> 

$(“#搜索”)。单击(函数(){
$(“#include”).load(“admin_search.php”);
});
$(“#添加”)。单击(函数(){
$(“#include”).load(“include/test.html”);
});
$('#user').submit(函数(){//捕获表单的提交事件
$.ajax({//创建一个ajax调用。。。
数据:$(this).serialize(),//获取表单数据
类型:$(this.attr('POST'),//获取或发布
url:$(this.attr('admin\u user.php'),//要调用的文件
成功:函数(响应){//on success。。
$('#include').html(响应);//更新DIV
}
});
return false;//取消原始事件以阻止表单提交
});
这是我的admin_search.php文件,如果不明显,jQuery会在我的索引文件中加载它:

<section>
<div>
    <header>
        <h2>Buscar información de usuario</h2>
    </header>

    <p>Para buscar un usuario o su información relacionada, ingresa el correo electrónico con el que el usuario se identifica.</p>

    <form id="user">
        <div class="row">
            <div>
                <input type="text" name="email" id="email" placeholder="Correo electrónico">
            </div>

            <div>
                <input type="submit" name="submit" value="Buscar usuario">
            </div>
        </div>
    </form>
</div>

乌萨里奥巴士公司
在通常的情况下,信息和关系都会发生变化,因此,我们需要对电气设备进行识别

理论上,我应该从我的#include DIV中的admin_user.php获得结果,但我什么也没有得到

有人能给我一些建议吗

编辑:这是我的admin_user.php文件

<?php

require_once('admin_connect.php');
$email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
$query = $con->query("SELECT * FROM user_data WHERE email = '$email'");

echo("
<table cellspacing='0'>
    <thead>
        <tr>
            <th></th>
            <th>VALORES</th>
        </tr>
    </thead>");

while ($row = $query->fetch(PDO::FETCH_ASSOC)) {

echo("
    <tbody>
        <tr>
            <td>Nombre</td>
            <td>"); echo $row['name']; echo("</td>
        </tr><!-- Table Row -->
        <tr class='even'>
            <td>Correo electrónico</td>
            <td>"); echo $row['email']; echo("</td>
        </tr><!-- Darker Table Row -->
        <tr>
            <td>Edad</td>
            <td>"); echo $row['age']; echo("</td>
        </tr>
        <tr class='even'>
            <td>Sexo</td>
            <td>"); echo $row['gender']; echo("</td>
        </tr>
        <tr>
            <td>Peso:</td>
            <td>"); echo $row['weight']; echo("</td>
        </tr>
        <tr class='even'>
            <td>Estatura</td>
            <td>"); echo $row['height']; echo("</td>
        </tr>
        <tr>
            <td>Problemas de salud</td>
            <td>"); echo $row['health_problem']; echo("</td>
        </tr>
        <tr class='even'>
            <td>Actividad física</td>
            <td>"); echo $row['activity']; echo("</td>
        </tr>
        <tr>
            <td>Alergias</td>
            <td>"); echo $row['food_sick']; echo("</td>
        </tr>
        </tbody>
    </table>");
}
?>

在您的
$.ajax
函数中,
type
属性应该如下:
键入:“POST”
。而且
url
应该是这样的:
url:'admin\u user.php'
。另外,我也不确定ajax函数中的
$(this)
是否引用了您正在考虑的
self
,因此我将该行显式更改为:
$('#user')。serialize()

另外,您可能希望将
error
函数添加到
ajax
调用中

编辑 加载表单后需要运行AJAX函数调用,因此这将位于
$(“#search”)中。加载表单后,单击
方法

总的来说,它看起来是这样的:

$("#search").click(function(){
    $("#include").load("admin_search.php");
    $('#user').submit(function() { // catch the form's submit event
        $.ajax({ // create an AJAX call...
            data: $('#user').serialize(), // get the form data
            type: 'POST', // GET or POST
            url: 'admin_user.php', // the file to call
            success: function(response) { // on success..
                $('#include').html(response); // update the DIV
            },
            error: function(jqXHR, textStatus, errorThrown){
                alert(textStatus);
            }
        });
        return false; // cancel original event to prevent form submitting
    });
});

$.ajax
函数中,
type
属性应该是这样的:
type:'POST'
。而且
url
应该是这样的:
url:'admin\u user.php'
。另外,我也不确定ajax函数中的
$(this)
是否引用了您正在考虑的
self
,因此我将该行显式更改为:
$('#user')。serialize()

另外,您可能希望将
error
函数添加到
ajax
调用中

编辑 加载表单后需要运行AJAX函数调用,因此这将位于
$(“#search”)中。加载表单后,单击
方法

总的来说,它看起来是这样的:

$("#search").click(function(){
    $("#include").load("admin_search.php");
    $('#user').submit(function() { // catch the form's submit event
        $.ajax({ // create an AJAX call...
            data: $('#user').serialize(), // get the form data
            type: 'POST', // GET or POST
            url: 'admin_user.php', // the file to call
            success: function(response) { // on success..
                $('#include').html(response); // update the DIV
            },
            error: function(jqXHR, textStatus, errorThrown){
                alert(textStatus);
            }
        });
        return false; // cancel original event to prevent form submitting
    });
});

您是否在浏览器的开发人员工具中观看了AJAX请求/响应?您是否将jQuery库包括在项目中?是否报告了任何错误?你是在网络服务器上运行的吗?@JayBlanchard似乎根本没有得到响应。是的,我有。不,没有。是的,我是。你试过用
$(document.ready()
?@u mulder包装吗?它破坏了管理员搜索加载。你看过浏览器开发工具中的AJAX请求/响应吗?您是否将jQuery库包括在项目中?是否报告了任何错误?你是在网络服务器上运行的吗?@JayBlanchard似乎根本没有得到响应。是的,我有。不,没有。是的,我是。你试过用
$(document).ready()包装吗?@u\u mulder破坏了管理员搜索加载。仍然没有为我做任何事情:(如果我使用HTML方式,它不会有任何问题,但无法使用jQuery加载任何内容。@S.Martell刚刚在您的问题中注意到,您从未关闭
admin\u search.php
文件中的
标记。我只是在复制粘贴时错过了该标记。它就在那里。我没有收到任何错误,但我看到了:Request Method:Get,在开发工具的标题上。可能是这样吗?是否可以包含
admin_user.php
文件中的代码?如果在
success
函数中设置了一个检查点,也可以在
$('#include').html(响应)上
line,您的程序是否达到了检查点?我已经在我的原始帖子中添加了admin_user.php。我将尝试检查点。仍然没有为我做任何事情:(如果我使用HTML方式,它不会有任何问题,但无法使用jQuery加载任何内容。@S.Martell刚刚在您的问题中注意到,您从未关闭
admin\u search.php
文件中的
标记。我只是在复制粘贴时错过了该标记。它就在那里。我没有收到任何错误,但我看到了:Request Method:Get,在开发工具的标题上。可能是这样吗?是否可以包含
admin_user.php
文件中的代码?如果在
success
函数中设置了一个检查点,也可以在
$('#include').html(响应)上
line,您的程序是否达到了检查点?我已将admin_user.php添加到我的原始帖子中。我将尝试检查点。