<script language="javascript">
function batch_update_amp(index) {
    var ic_id = $('#cache_ic_id_' + index).val();
    var msg_obj = "#cache" + index;
    var amp_code = '';
    $(msg_obj).html("\u7a0d\u7b49...");

    $.ajax({
        type: "get",
        dataType: "json",
        url: "<?php echo site_url('information/update_www_cache/') ?>/" + ic_id,
        success: function (result, textStatus) {
            //当result为空的时候跳过
            if (result.length == 0 || result == '' || undefined || null) {
                $(msg_obj).html("<a href='javascript:void(0);' onclick='create_amp_data(" + index + ");' >发生错误，请重试</a>");
                create_amp_data(++index);
                return;
            }

            if (result.name === 'no') {
                $(msg_obj).html("更新失败: " + result.data);
            } else {
                $(msg_obj).html("更新成功!");
            }
            create_amp_data(++index);

        },
        error: function () {
            $(msg_obj).html("<a href='javascript:void(0);' onclick='create_amp_data(" + index + ");' >发生错误，请重试</a>");
            create_amp_data(++index);
        }
    });
}

function create_amp_data(index) {
    if ($('#cache_url' + index).length > 0) {
        setTimeout("batch_update_amp(" + index + ")", 100);
    }
}

</script>

<div class="row-fluid">
    <div class="span1">

    </div>

    <div class="span10">

        <table class="table table-striped">
            <thead>
                <tr>
                    <th class="span1">#</th>
                    <th class="span9">URL</th>
                    <th class="span2">更新进度</th>
                </tr>
            </thead>
            <tbody>
                <?php
				$i=0;
                foreach ($all_information as $key => $info) {
                    if ($info->ic_status == 1 && !empty($info->ic_url)) {
						$i++;
                        ?>
                        <tr>
                            <td><?php echo $i; ?></td>
                            <td id="cache_url<?php echo $i; ?>" name="cache_url<?php echo $i ; ?>" class="cache_url"><?php echo $info->ic_url; ?></a></td>
                            <input type="hidden" id="cache_ic_id_<?php echo $i; ?>"
                                   value="<?php echo $info->ic_id; ?>"/>
                            <td id="cache<?php echo $i ; ?>" name="cache<?php echo $i ; ?>"><i class="icon-refresh"></i></td>
                        </tr>
                    <?php }
                } ?> 
            </tbody>
        </table>
    </div>

    <div class="span1">
<a href="javascript:void(0);" class="btn btn-danger" onclick="create_amp_data(1);">开始更新</a>
    </div>


</div>


