日期:2014-05-16  浏览次数:20802 次

js调用后台数据,在页面显示时,样式和js方法都没加载上 - Web 开发 / Ajax
我用的是DataTables 控件
页面调用

HTML code

<style type="text/css" title="currentStyle">
    @import "js/datatables/css/demo_page.css";
    @import "js/datatables/css/demo_table.css";
</style>
<script type="text/javascript" language="javascript" src="js/datatables/js/jquery.js"></script>
<script type="text/javascript" language="javascript" src="js/datatables/js/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8">
            $(document).ready(function() {
                $('#example').dataTable( {
                    "sPaginationType": "full_numbers"
                } );
            } );
</script>    


后台发送的数据
Java code

String test;
test="<table cellpadding='0' cellspacing='0' border='0' class='display' id='example'>"+
      "<thead><tr><th>aa</th><th>bb</th><th>cc</th><th>dd</th></tr></thead>"+
      "<tbody>"+
      "<tr><td>a</td><td>b</td><td>c</td><td>d</td></tr>"+
      "<tr><td>1</td><td>2</td><td>3</td><td>4</td></tr>"+
      "</tbody></table>";

try {
    response.getWriter().write(test);
    } catch (IOException e) {
      e.printStackTrace();
    }



后台js接收数据
JScript code

        var reportrs = req_report.responseText;    
        document.getElementById('dynamic').innerHTML=reportrs;



前台有一个div用来接收数据
HTML code

  <div id="dynamic"></div>



问题是数据是显示出来了,但是样式和DataTables 的方法没有加载上去,
  请问这个是怎么回事?
  怎么解决?
谢谢大家!~

------解决方案--------------------
1.推荐用link的方法载入css文件。
2.JQuery我不了解,但是"sPaginationType": "full_numbers"你确定这行代码没问题?属性名不需要加双引号
3.还不行的话用firebug调试。
------解决方案--------------------
你可以用火狐浏览器调试下,看看css是否已经加载上了,还有用ajax动态加载的表!要是方便的话把例子发上来大家可以一起找找原因。