无法为从Ajax调用加载的html加载css / js

时间:2015-09-28 08:31:42

标签: javascript html css ajax cgi

我正在为一个非常小的应用程序使用CGI脚本,我从文本框向数据库发送请求并接收一些数据并将其显示在同一个网页上。我在文本框页面上有以下HTML:

<html>
<head>
<title>Text Search</title>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="https://jqueryui.com/resources/demos/style.css">
<script type="text/javascript">
    function xmlhttpPost() {
        var xmlHttpReq = false;
        var self = this;
        if (window.XMLHttpRequest) {
            self.xmlHttpReq = new XMLHttpRequest();
        }
        else if (window.ActiveXObject) {
            self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
        }
        self.xmlHttpReq.open("POST", "test2.py", true);
        self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        self.xmlHttpReq.onreadystatechange = function() {
            if (self.xmlHttpReq.readyState == 4) {
                updatepage(self.xmlHttpReq.responseText);
            }
        }
        self.xmlHttpReq.send(getquerystring());
    }
    function getquerystring() {
        var form = document.forms["search_form"];
        var word = form.word.value;
        qstr = 'q=' + escape(word);
        alert(qstr);
        return qstr;
    }
    function updatepage(str){
        alert(str);
        document.getElementById("result").innerHTML = str;
    }
    $(function() {
        $( "#tabs" ).tabs();
    });
</script>
</head>
<body>
<form name="search_form">
    <p>
        Query: <input name="word" type="text">
        <input value="Submit" type="button" onclick='JavaScript:xmlhttpPost()'>
    </p>
    <div id="result">
    </div>
</form>
</body>
</html>

我提交短信后,会收到<table>...</table>之类的

<table width=100% height=100%>
<tr>
<td width=80%>
<div id="tabs" style="width: 1200px;">
    <ul>
<li><a href="#tabs-151802">donald</a></li></ul>
<div id="tabs-151802">

<div id="1" class="151802">
<h2>1.  Index of World War II articles (D) - Wikipedia, the free encyclopedia</h2><br>
<a href=http://en.wikipedia.org/wiki/Index_of_World_War_II_articles_(D) target="_blank">http://en.wikipedia.org/wiki/Index_of_World_War_II_articles_(D)</a><br><br>
</div>
<hr>
</div>

</div>
</td>
<td width=20% valign="top" style="font-size: initial;">
</td>
</tr>
</table>
来自test2.py

显示在<div id="result"></div>之间。该应用程序工作正常,但我不能让CSS / JS为我收到的内容工作!我希望使用与查询页面的HTML相同的脚本(js / css)。

如果我在没有调用ajax的情况下渲染页面,则css / js可以正常工作。

更新: 我注意到没有加载CSS。 javascript现在可以忽略了。 style.css font-familyfont-sizebody function gh_view_categories(){ $a='<table>'; $a.='<tr>'; $a.='<td><strong>'.'Categoria:'.'</strong></td>'; $a.='<td><strong>'.'Soglia minima:'.'</strong></td>'; $a.='<td><strong>'.'Tot attuale:'.'</strong></td>'; $a.='<td><strong>'.'Crea ordine'.'</strong></td>'; $a.='</tr>'; $query = db_select('uc_product_classes', 'u') ->fields('u', array('name','soglia', 'totattuale')); $result = $query->execute(); while ($record = $result->fetchAssoc()) { $idUser=gh_get_user_id($record['name']); $a.='<tr>'; $a.='<td>'.$record['name'].'</td>'; $a.='<td>'.$record['soglia'].'</td>'; $a.='<td>'.$record['totattuale'].'</td>'; $a.='<td>'.l('BUTTON', FUNCTION($idUser)')).'</td>'; $a.='</tr>'; } $a.='</table>'; return $a; } 。这些都没有加载。

0 个答案:

没有答案