Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.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
Javascript 数据未获取PHP MYSQL AJAX_Javascript_Php_Jquery_Mysql_Ajax - Fatal编程技术网

Javascript 数据未获取PHP MYSQL AJAX

Javascript 数据未获取PHP MYSQL AJAX,javascript,php,jquery,mysql,ajax,Javascript,Php,Jquery,Mysql,Ajax,我有一个带有月份名称的选择菜单(值是从1到12的数字): 在里面,我想从数据库中获取数据。因此,如果选择十月,则显示十月的锦标赛等等 SQL代码是正确的(经过测试) 看起来ajax甚至找不到fetch_tournaments.php文件。。。或者只是在某个地方我犯了个错误 我的AJAX: $(document).ready(function(){ $('#monthSelector').change(function(){ var month = $(this).va

我有一个带有月份名称的选择菜单(值是从1到12的数字):

在里面,我想从数据库中获取数据。因此,如果选择十月,则显示十月的锦标赛等等

SQL代码是正确的(经过测试)

看起来ajax甚至找不到fetch_tournaments.php文件。。。或者只是在某个地方我犯了个错误

我的AJAX:

$(document).ready(function(){

    $('#monthSelector').change(function(){

        var month = $(this).val();

        alert(month);

        $.ajax({

            url:"../../includes/functions/ajax/fetch_tournaments.php",
            method:"POST",
            data:{month: month},
            dataType:"text",
            success:function(data)
            {
                $('#tournamentList').html(data);
            }

        });

    });

});
fetch_tournaments.php:

<?php

require_once '../../../config/init.php';

$sql = "SELECT * FROM tournaments WHERE itfnt = 'ITF' AND MONTH(date) = '".$_POST["month"]."' ORDER BY date ASC";
$result = $mysqli->query($sql);
$num_rows = $result->num_rows;
if($num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        echo '<div class="col-md-6">
                <div class="card">
                    <div class="card-block">
                        <h6 class="category text-danger">
                            <i class="now-ui-icons location_pin"></i> Latvia, Riga
                        </h6>
                        <h5 class="card-title">
                            <a href="#pablo">RIGA AUTUMN CUP 1</a>
                        </h5>
                        <div class="card-footer">
                            <div class="author">
                                <img src="assets/img/lpts.png" alt="..." class="avatar img-raised">
                                <span>LPTS</span>
                            </div>
                             <div class="stats stats-right">
                                <i class="now-ui-icons ui-1_calendar-60"></i> 25.10.17
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            ';
    }
} else {
    echo 'No tournaments that month';
}

?>


解决了。。。首先,我不知道您的文件夹结构,您是否尝试将两个文件都放在同一个文件夹中,可能您在包含php文件时遇到了问题

我认为这是我们应该做的第一件事

您确定url:
“../../includes/funitions/ajax/fetch\u tournaments.php”
是否可以在浏览器中访问(因为您无法链接到非公共资源)? 您应该避免在URL中使用../..,并且您的链接应该从/或按照完整路径开始。与您一起学习。我建议使用
PDO
,我希望它比使用非参数化查询更加简单、干净、安全。此外,还可以帮助您在
MySQLi
PDO