Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
69 views
in Technique[技术] by (71.8m points)

javascript - data is not coming from ajax

i have a php script. I am fetching some of the data in the form with ajax. data comes with ajax, but when I run this form, it does not post the values from ajax. It gives an error Undefined index:......

ajax script:

$(document).ready(function(){
    $('#tur').on('change',function(){
        var turID = $(this).val();
        if(turID){
            $.ajax({
                type:'POST',
                url:'ajaxRez.php',
                data:'tur_id='+turID,
                success:function(html){
                    $('#turadi').html(html);

                }
            }); 
        }else{
            $('#turadi').html('<b>?nce Tur Türünü Se?in</b>');
        }
    });   
});

and this is my form

<tr>
                        <td><b>Tur Türü:</b> </td>
                        <td>
                            <select class="custom-select" name="tur" id="tur">
                                <option value="">Lütfen Se?in</option>
                                <option value="gunluk">Günlük Tur</option>
                                <option value="cokgunlu">?ok Günlük Tur</option>
                                <option value="ozeltur">?zel Tur</option>
                                <option value="ozeltur">Kiralama</option>
                            </select>
                        </td>
                        <td><b>Tur Ad?:</b> </td>
                        <td>
                        <div  id="turadi" > <b>Tur se?imi yap?n</b>
                        </div>
                            
                        </td>
                    </tr>

and ajaxRez.php file:

include('config.php');

if(isset($_POST["tur_id"])){
    //Datalar? ?ek
    $tur_id= $_POST['tur_id'];
    $bugun = date('Y-m-d H:m:s');
    
        if ($tur_id=="gunluk") {
            $query = "SELECT * FROM events WHERE color LIKE '#0071c5' AND start >= '$bugun' ORDER BY start ASC";                            // mavi günlük
        }elseif ($tur_id=="cokgunlu") {
            $query = "SELECT * FROM events WHERE color LIKE '#008000' OR color LIKE '#40E0D0' AND start >= '$bugun' ORDER BY start ASC"; }  // turkuaz ve ye?il otel ve tekne
        elseif ($tur_id=="ozeltur") {
            $query = "SELECT * FROM events WHERE color LIKE '#FFD700' AND start < '$bugun' ORDER BY start ASC"; }                           // sar? ?zel tur
        elseif ($tur_id=="kiralama") {
            $query = "SELECT * FROM events WHERE color LIKE '#FF0000' AND start < '$bugun' ORDER BY start ASC"; }                           // k?rm?z? kiralama
    
    $run_query = mysqli_query($link, $query);
    
    //Sonu?lar? say
    $count = mysqli_num_rows($run_query);
    
    //Turlar?n listesini ??kart
    if($count > 0){
        echo '
        <select class="custom-select" name="turadi" >
        <option value="">Lütfen Se?in</option>';
        while($row = $run_query->fetch_assoc()){
        $id=$row['id'];
        $baslik=$row['title'];
        $tarih=tarihDuzenle(tarihduzelt($row['start']));
        echo "<option value='$id'> $baslik / $tarih</option>";
        } echo "</select>";
    }else{ ?>
        Ba?lang??: <input type="text" class="form-control" id="datepicker" name="baslangic" placeholder="13/06/2021"/> Biti?: <input type="text" class="form-control" id="datepicker" name="bitis" placeholder="13/06/2021"/>
   <? }
}

Does anyone have an idea? There is (name="turadi") but it gives error undefined index Thanks

question from:https://stackoverflow.com/questions/65602484/data-is-not-coming-from-ajax

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...