簡體   English   中英

成功ajax函數內部的for循環

[英]For loop inside success ajax function

我有這個jQuery ajax:

$.ajax({
  type: 'POST',
  url: 'test.php',
  cache: false,
  data: 'action=find'+'&find_date=' + find_date + '&find_title='+ find_title + 
                            '&find_datestart='+ find_datestart + '&find_dateend='+ find_dateend + 
                            '&find_locationid='+ find_locationid + '&find_userid='+ find_userid + 
                            '&find_roomid='+ find_roomid + 
                            '&find_starttime='+ find_starttime + '&find_endtime='+ find_endtime,

    success: function(response){
        alert(response);
        $("#find").dialog('close');
        $('.remove').remove();
        $('#find_data').before('abcccccc');

        //location.reload();
        return false;
    }
});

這是我的HTML

foreach($GetSchduleData as $k => $schedule) {
                               ?>
                               <tr style="text-align: center;" class="remove">
                                <input type="hidden" name="class_id" value="<?php echo $schedule['class_id']; ?>">
                                <input type="hidden" name="class_type_id" value="<?php echo $schedule['class_type_id']; ?>">
                                <input type="hidden" name="type_description_abbr" value="<?php echo $schedule['type_description_abbr']; ?>">
                                <td class="scheduletd"><input type="checkbox" title="selectUnselect" onclick="" id="selectUnselect"></td>
                                <td class="scheduletd"><?php echo $i; ?></td>
                                <td class="scheduletd"><?php echo $schedule['timestart'];?></td>
                                <td class="scheduletd"><?php echo $schedule['timeend'];?></td>
                                <td class="scheduletd"><div class="type_meeting <?php echo $schedule['type_description_abbr'] ?>" id="<?php echo $schedule['class_id'];?>type"></div> </td>
                                <td class="scheduletd"><?php echo $schedule['s_title'];?></td>
                                <td class="scheduletd"><?php echo $schedule['instructor'];?></td>
                                <td class="scheduletd">Sub?</td>
                                <td class="scheduletd"><?php echo $schedule['location_name'];?></td>
                                <td class="scheduletd"><?php echo $schedule['class_room'];?></td>
                                <td class="scheduletd"><?php  echo $schedule['Show_online'];?></td>
                                <td class="scheduletd"><?php ?>Product</td>
                                <td ><?php ?>Enrolled</td>
                               </tr> 
                               <?php 
                                 $i++;
                                }
                                ?>
                            <tr id="find_data">
                            </tr>

在此處輸入圖片說明 我想成功使用響應替換該tr作為響應,我得到了array但是我想在成功內部執行一個for循環。 怎么可能?

像這樣使用

  $.ajax({
        type: 'POST',
        url: 'test.php',
        cache: false,
        dataType: "json",
        data: 'action=find' + '&find_date=' + find_date + '&find_title=' + find_title +
    '&find_datestart=' + find_datestart + '&find_dateend=' + find_dateend +
    '&find_locationid=' + find_locationid + '&find_userid=' + find_userid +
    '&find_roomid=' + find_roomid +
    '&find_starttime=' + find_starttime + '&find_endtime=' + find_endtime,

        success: function (response) {
            for (i = 0; i < response.length; i++) {
                alert(response[i].class_id);
            }

            $("#find").dialog('close');
            $('.remove').remove();
            $('#find_data').before('abcccccc');

            //location.reload();
            return false;
        }
    }); 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM