php - CSS 不适用于 ajax 响应

标签 php jquery css ajax

我希望将外部 CSS 应用于 ajax 响应。 我正在尝试创建一个页面,在用户选择表单中的选项并提交后,另一个表单通过 ajax 加载。但是 CSS 不适用于 ajax 响应。 我无法找出错误。方法不对请指正。

$('#getStudents').submit(function(e) {
  e.preventDefault();
  $.ajax({
    url: 'feature1/getStudents.php',
    type: 'POST',
    data: $('#getStudents').serialize(),
    cache: false,
    success: function(returndata) {
      //alert(returndata);            
      $("#listStudents").html(returndata);
    }
  });
});

这就是问题所在。在第 4 列 css 未应用。 复选框应显示为 ios 开关 ( http://abpetkov.github.io/switchery/ )

    <?php


    $output='';

    $output = $output. '
    <div class="panel panel-white">
    <div class="panel-heading clearfix">
        <h3 class="panel-title"> Students </h3>
    </div>
    <div class="panel-body">

        <div class="table-responsive">
            <table id="students" class="display table" style="width: 100%; cellspacing: 0;">
                <thead>
                    <tr>
                        <th> ID</th>
                        <th>Student ID</th>
                        <th>Name</th>
                        <th>Attendance</th>                        
                    </tr>
                </thead>
                <tfoot>
                    <tr>
                        <th> ID</th>
                        <th>Student ID</th>
                        <th>Name</th>
                        <th>Attendance</th>
                    </tr>
                </tfoot>
                <tbody>';
                $i=1;
                while($data = mysqli_fetch_assoc($results)) {
                    $output = $output. '<tr>
                        <td>'.$i++.'</td>
                        <td>'.$data["id"].'</td>
                        <td>'.$data["id"].'</td>
                        <td>
                        <div class="ios-switch pull-right switch-md">
                            <input type="checkbox" class="js-switch pull-right fixed-header-check" checked>
                        </div>
                        </td>
                    </tr>'; 
                }

    $output = $output. '
                </tbody>
            </table>  
        </div>
    </div>
    </div>'; 


    echo $output;  

    mysqli_close($con);

    ?>

最佳答案

这是因为您的包含所有 css 的 html 页面在文档准备就绪时被加载..它读取所有类并根据它应用的样式表..但是在 ajax 中我们加载另一个页面相同的 html 页面,这次浏览器没有将 html 类映射到样式表,这就是为什么你的 css 没有应用在上面

关于php - CSS 不适用于 ajax 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42174634/

相关文章:

javascript - 在 Backbone Marionette View 之间进行通信

php - 根据 php echo 值更改 td bg 颜色

php - 使用PHP中的API使用YouTube搜索YouTube,搜索词中包含多个单词

PHP rand() 排除某些数字

php - Paypal html按钮自定义字段限制

javascript - html select onchange 获取自定义属性值设置为其他输入值

php - jquery ajax 结果消息

html - 如果用户运行广告拦截器,如何制作显示消息的广告包装器?

html - 等高 float 部分(仅限 CSS)

php - 从 php 脚本执行 proc_open 以连接到 pgsql 时出错