从先前通过jQuery

时间:2016-11-11 21:43:35

标签: php jquery ajax

我正在开发一种工具,通过Web界面描述数据库中的表。我有一个用户选择数据库版本的下拉列表。该选择使用表中的列填充表单选择。问题是,当我从该列表中选择一个适当通过Ajax的列时,select的结果是从我的else语句而不是用户选择的数据库中对我的默认数据库运行的。当我尝试将db版本发送到search.php

时,我在某处出现故障

我的jQuery:

$(document).on("click", '.version', function() {
    var myVersion = $(this).attr('id');
    //$.post('conn.php', {'myVersion': myVersion});
    $('#select').load('selectdb.php', {'myVersion': myVersion});
    $.post('search.php', {'dbVersion': myVersion});
});

$(document).on('click', '#search', function() {
    var formData = $('#schemaSearch').serializeArray();
    $('#searchResults').load('search.php', formData);
});

selectdb.php:

<?php

include('conn.php');

if ($myVersion == '9.93') {
    $dbVersion = 'goals';
} else {
    $dbVersion = 'jamfsoftware';
}

$columnOnly = mysql_query("select distinct(column_name) from information_schema.columns where table_schema='" . $dbVersion . "' order by column_name");
$result = mysql_query("select table_name, column_name from information_schema.columns where table_schema='" . $dbVersion . "' order by column_name");


   echo  '<option></option>';

    while($row = mysql_fetch_array($columnOnly)) {
        echo "<option value=" . $row['column_name'] . ">" . $row['column_name'] . "</option>";
    } 

?>

的search.php:

<?php
    include('conn.php');
    include('selectdb.php');

    $lookingFor = $_POST['select'];
    if (isset($_POST['dbVersion'])) {
        $dbVersion = $_POST['dbVersion'];
    } else {
        $dbVersion = 'jamfsoftware';
    }



    $lookingForQuery = mysql_query("select table_name, column_name from information_schema.columns where table_schema='" . $dbVersion . "' and column_name like '" . $lookingFor . "'");
    echo $dbVersion;
?>

0 个答案:

没有答案