Query SQL does not work in ajax jquery

I have a little problem with my code, I want to execution query using ajax, but the query does not run. Is there an error in my code? Here’s Query SQL :

SELECT * FROM event WHERE date = '2015-05-28' ORDER BY start_time ASC

Here’s my code :


$(document).ready(function(){ $(".btn-load").click(function(){ $.ajax({ type : "POST", url : "show.php", data: "date='2015-05-28'", success: function(data){ $(".show").html(data); } }); }); });

Show.php :

require 'database.php';
$pdo = Database::connect();
$date = $_POST['date'];
$sql = "SELECT * FROM event WHERE date = '".$date."' ORDER BY start_time ASC";
     foreach ($pdo->query($sql) as $row) {
            echo "

$row[name]

"; echo "

$row[date]

"; } Database::disconnect();

Try this

var post_data = {};
post_data['date'] = '2015-05-28';

$.ajax({
    type : "POST",
    url : "show.php",
    data: post_data,
    success: function(data){
        $(".show").html(data);
    }
});

Also, i recommend using prepared statement on your query, since youre already using PDO. Make the most out of it

Hello, buddy!责编内容来自:Hello, buddy! (源链) | 更多关于

阅读提示:酷辣虫无法对本内容的真实性提供任何保证,请自行验证并承担相关的风险与后果!
本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 后端存储 » Query SQL does not work in ajax jquery

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录