PHP AJAX XMLHTTPRequest会话总是被破坏而不会破坏它

时间:2016-11-25 07:31:34

标签: php jquery ajax xmlhttprequest session-variables

我能够确认我的SESSION变量将包含一个值,但是下次我运行我的函数时会说:注意:未定义的变量:第94行的C:\ xampp \ htdocs \ Reports_db \ getvalue.php中的_SESSION

我认为会话将​​保留其值,除非会话被销毁?为什么我没有得到会话的价值?有什么想法吗?

这是PHP文件(UI)

<!DOCTYPE html>

<?php include ('includes/header.php');?>

<navigation>
    <div id="nav-bar">
        <ul class="nav nav-pills nav-justified">
            <li role="p_resentation"><a href="index.php">Home</a></li>
            <li role="p_resentation" class="active"><a href="#">Sales</a></li>
            <li role="p_resentation"><a href="manufacturing.php">Manufacturing</a></li>
        </ul>
    </div>
</navigation>
<br />

<div class="row" id="row1">
    <div class="col-sm-8" id="row1-sm8">
        <div class="panel panel-default">
            <div class="panel-heading" id="content-heading">
                <form action"" class="form-inline">
                    <div class="form-group">
                        <select name="users" onchange="getvalue(this.value)" class="btn btn-default dropdown-toggle form-control" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
                            <option value="">Select a field:</option>
                            <option value="1">Product Name</option>
                            <option value="2">SO #</option>
                            <option value="3">Assembly Name</option>
                            <option value="4">Sales Person</option>
                            <option value="5">Customer Name</option>
                            <option value="6">PO / Remarks</option>
                            <option value="7">SO Status</option>
                            <option value="8">Delivery Status</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <div class="input-group">
                            <span class="input-group-addon" id="basic-addon1">@</span>
                            <input type="text" id="search" onchange="search(this.value)" class="form-control" placeholder="Username" aria-describedby="basic-addon1" value="">
                        </div>
                    </div>
                    <div class="form-group">
                        <input type="button" id="search_btn" onclick="search(this.value)" class="form-control" placeholder="Username" aria-describedby="basic-addon1" value="">
                    </div>
                </form>
            </div>
            <div>
                <table class="table">
                    <div class="panel-body" id="output">

                    </div>
                </table>
            </div>
        </div>
    </div>
    <div class="col-sm-4" id="row1-sm4">
        <div class="panel panel-default">
            <div class="panel-heading" id="login-heading">Filters</div>
            <div class="panel-body">
                <div class="row">
                    <div class="col-sm-12">
                        <br/>
                        <table class="table">
                            <tr>
                                <td>Field</td>
                                <td>Value</td>
                            </tr>
                        </table>
                    </div>
                </div><br />
            </div>
        </div>
    </div>
</div>

<?php include ('includes/footer.php'); ?>

<script>
function getvalue(str) {
    if (str == "") {
        document.getElementById("output").innerHTML = "";
        return;
    } else { 
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
                document.getElementById("output").innerHTML = this.responseText;
            }
        };
        xmlhttp.open("GET","_db/getvalue.php?q="+str,true);
        xmlhttp.send();
    }
}
function search(str) {

    if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    } else {
        // code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            document.getElementById("output").innerHTML = this.responseText;
        }
    };
    xmlhttp.open("GET","_db/getvalue.php?q=9",true);
    xmlhttp.send();
}

$(document).ready(function(){
    $("#search_btn").click(function(){
        var x = $("#search").val();
        search(x);
    });
    $("#search").keyup  (function(){
        var x = $("#search").val();
        search(x);
    });
});
</script>

以下是我使用会话的代码

<html>
<body>
    <table class="table">
<?php
    include('../includes/links/js.php');
    include('../includes/links/css.php');
    include('/connection/connect.php');
    if (isset($_GET['q'])){

        $val = $_GET['q'];
        if ($val < 9) {
            $field = '';
            $field_s = '';
            $group = '';

            if ($val == 1) {
                $field = "(SELECT pp1.name_template FROM product_product pp1 WHERE boml.product_id = pp1.id) as BOML";
                $field_s ="(SELECT pp1.name_template FROM product_product pp1 WHERE boml.product_id = pp1.id)";
                $group = "BOML";
            } elseif ($val == 2) {
                $field == "so.name";
                $group = "SO";
                $field_s = "so.name";
            } elseif ($val == 3) {
                $field = "sol.name as assembly";
                $group = "assembly";
                $field_s = "sol.name";
            } elseif ($val == 4) {
                $field = "split_part(u.login, '@', 1) as sales_person";
                $group = "sales_person";
                $field_s = "split_part(u.login, '@', 1)";
            } elseif ($val == 5) {
                $field = "c.display_name as Customer";
                $group = "Customer";
                $field_s = "c.display_name";
            } elseif ($val == 6) {
                $field = "so.note as PO";
                $group = "PO";
                $field_s = "so.note";
            } elseif ($val == 7) {
                $field = "so.state as Status";
                $group = "Status";
                $field_s = "so.state";
            } elseif ($val == 8) {
                $field = "COALESCE(del.state, 'Waiting Availability') del_status";
                $group = "del_status";
                $field_s = "COALESCE(del.state, 'Waiting Availability')";
            }
            $query = "      FROM sale_order so

                            INNER JOIN sale_order_line sol
                                ON so.id = sol.order_id
                            INNER JOIN res_partner as c
                                ON so.partner_id = c.id
                            LEFT JOIN account_payment_term as ap
                                ON so.payment_term_id = ap.id
                            INNER JOIN product_uom as pu
                                ON sol.product_uom = pu.id
                            LEFT JOIN account_tax_sale_order_line_rel as acs
                                ON sol.id = acs.sale_order_line_id
                            LEFT JOIN account_tax as at
                                ON acs.account_tax_id = at.id
                            INNER JOIN product_template as pt
                                ON sol.product_id = pt.id
                            LEFT JOIN mrp_bom as bom
                                ON pt.id = bom.product_tmpl_id
                            LEFT JOIN mrp_bom_line as boml
                                ON bom.id = boml.bom_id
                            INNER JOIN res_users as u
                                On so.create_uid = u.id

                            Left    Join (Select sp1.id, sp1.origin, sp1.state, spo1.qty_done, spo1.product_id, spo1.picking_id, sp1.date_done
                                            From stock_picking as sp1
                                            Full    Join stock_pack_operation as spo1
                                            On          sp1.id = spo1.picking_id) as del
                            On      so.name = del.origin
                            And     sol.product_id = del.product_id";

            if ($val != 2){
                $query = "
                            SELECT      Distinct ".$field." ".$query." Order By ".$group;
                            $_SESSION['being_used'] = "SELECT       Distinct ".$field." ".$query;
                            $_SESSION['field'] = $field;
                            echo 'set ok';
            } else {
                $query = "
                            SELECT      Distinct so.name ".$query." Order By so.name DESC";
                            echo 'set ok';
                            $_SESSION['being_used'] = "SELECT       Distinct so.name ".$query;
                            $_SESSION['field'] = $field;
                            echo 'set ok';
            }
        } else {
                echo $_SESSION['being_used'];
                echo $val;
                $search = $_GET['q'];
                $field_s = $_SESSION['field'];
                $query = $_SESSION['being_used']." Where".$field_s." Like '%".$search."%'";
        }
        $result = pg_query($query);
        while($row = pg_fetch_row($result)){
            echo "<tr>";
            echo "<td>" . $row[0] . "</td>";
            echo "</tr>";
        }
    }

?>
    </table>
</body>
</html>

请不要再查看查询,因为我唯一的问题是SESSION我不知道为什么它会被毁坏。 TIA ppl!

0 个答案:

没有答案