尝试根据之前的2个选择

时间:2017-12-29 12:57:28

标签: javascript php jquery ajax pdo

您能否在以下代码中找出问题所在 我正在尝试根据之前的2个选择选项填充1个选择选项。 例如,您将选择选项1,然后根据这两个选项选择选项2我将获得第三个选项。 这是我的jquery部分

/*This Is Basically My Jquery Part Which will Take 2 values from selects*/
$(".asset").change(function(){

    var id=$(this).val();
    console.log(id);
    var dataString1 = 'id='+ encodeURIComponent(id);
    console.log(dataString1);

    $(".amc").change(function(){

        var aid=$(this).val();
        console.log(aid);
        var dataString2 = 'aid='+ encodeURIComponent(aid);
        console.log(dataString2);

        //console.log(data);
        $.ajax({
            type: "POST",
            url: "fetch.php",
            data : {dataString1: id,dataString2: aid},
            cache: false,
            success: function(html)
            {
                $(".scheme").html(html);
            } 
        });

    });

});

这是获取部分

<?php
include('dbconfig.php');


if($_POST['id'] && $_POST['aid'])
{

    $id=$_POST['id'];
    $aid=$_POST['aid'];



    $stmt = $DB_con->prepare("SELECT * FROM Master_MutualFundMasters WHERE AssetClassID=:id AND AMCID = :aid");
    $stmt->execute(array(':id' => $id));
    $stmt->execute(array(':aid' => $aid));


    ?><option selected="selected">Select City :</option>
    <?php while($row=$stmt->fetch(PDO::FETCH_ASSOC))
    {
        ?>
        <option value="<?php echo $row['WW_UniqueInvestmentCode']; ?>"><?php echo $row['PrimarySchemeName']; ?></option>
        <?php
    }
}
?>

当我检查我的控制台时,它会向我显示数据,但不会传递给下一页

2 个答案:

答案 0 :(得分:1)

你应该在开头使用select 例如:

<select>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="vw">VW</option>
  <option value="audi" selected>Audi</option>
</select>

答案 1 :(得分:0)

since you are asking 
In your console it is showing me the data but its not passing on next page means (fetch.php).
then you can do-

   $.ajax({
            type: "POST",
            url: "fetch.php",
            data : {"id":dataString1,"aid":dataString2},
            cache: false,
            success: function(html)
            {
                $(".scheme").html(html);
            } 
        });

and in fetch.php page.
if($_POST["id"] && $_POST["aid"])
{

    $id=$_POST["id"];
    $aid=$_POST["aid"];

    //write ur code here...
}   

I Hope this help u.