doushang1778 2016-01-12 13:54
浏览 17
已采纳

发送到$ _POST的Jquery var没有完成查询,返回错误

I've been trying to figure out what i'm doing wrong for a day now and tried all kinds of things to make this work.Basically i send a var named id through POST to a php file which then runs a query with it and brings back data. print_r shows that the correct data has been sent (a single number in this case)but instead of the query returning with the names etc it just doesn't recognise the $_POST['id'] and returns with an error.

$(document).ready(function() {
    $(".side-menu_description").click(function() {
        var id = $(this).attr("id");
        if ($.trim(id) != "") {
            /*
            $.post("index_loads/series_load.php", { 'id': id }, function(data) {
                alert(data);
                $("#wrap").fadeOut("slow").load("index_loads/series_load.php").fadeIn("slow");
            });
            */

            $.ajax({ 
                url: 'index_loads/series_load.php/',
                data: { "id": id },
                type: 'POST',
                success: function(data) {
                    $("#wrap").fadeOut("slow").load("index_loads/series_load.php").fadeIn("slow");
                    alert(data);
                },
                error: function(){
                    alert("Error: Could not return");
                }
            });
        }
    });
});
<?php 
    print_r($_POST);
    //$_POST['id'] = file_get_contents('php://input');

    $q = "SELECT * FROM Series WHERE SeriesID = '$_POST[id]'";
    $r = mysqli_query($dbc, $q);    
    $data = mysqli_fetch_assoc($r);
?>

The first few lines of the alert :

Array
(
    [id] => 5
)

<h1> </h1>
<!--<h2>

Airs At: <br />
<b>Notice</b>:  Undefined offset: 1 in <b>C:\xampp\htdocs\myname\index_loads\series_load.php</b> on line <b>24</b><br />
:   </h2>-->

<h3>Rating:<br> Stars + (4.0)</h3>

I've tried all kinds of things from using $.ajax to changing data to { "id=" + id} to file_get_contents but none of them seem to work. I'm probably missing something but after searching i still can't find the answer!

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • dongri1989 2016-01-12 13:59
    关注

    change

    $("#wrap").fadeOut("slow").load("index_loads/series_load.php").fadeIn("slow");
    

    to

    $("#wrap").fadeOut("slow").html(data).fadeIn("slow");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源