Ajax请求可以工作,但没有CSS和JavaScript

Ajax请求可以工作,但没有CSS和JavaScript,javascript,css,ajax,Javascript,Css,Ajax,下面是我为Ajax请求编写的代码片段。请求是有效的,但是当请求被处理时,页面显示时没有任何CSS或JS(即使我的所有内容都在同一个目录中)。为了测试这一点,我将请求指向我网站上已经存在的一个页面。有什么帮助吗?提前谢谢 <html> <head> <script type="text/javascript"> function loadXMLDoc() { var xmlhttp; if (window.XMLHttpRequest) { xmlhtt

下面是我为Ajax请求编写的代码片段。请求是有效的,但是当请求被处理时,页面显示时没有任何CSS或JS(即使我的所有内容都在同一个目录中)。为了测试这一点,我将请求指向我网站上已经存在的一个页面。有什么帮助吗?提前谢谢

<html>
<head>
<script type="text/javascript">
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","ajaxtest.html",true);
xmlhttp.send();
}
</script>
</head>
<body>
<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>
</body>
</html>
function csstuff() 
{
    $('selector').css('var', 'val');
}
function domWinInit(){ 
    //include the code from 
    (http://swip.codylindley.com/jquery.DOMWindow.js)
}

function domClick(){ 
    $('.defaultDOMWindow').openDOMWindow({ 
      eventType:'click', 
      loader:1, 
      loaderImagePath:'animationProcessing.gif', 
      loaderHeight:16, 
      loaderWidth:17 
    });  
}

函数loadXMLDoc()
{
var-xmlhttp;
if(window.XMLHttpRequest)
{
xmlhttp=新的XMLHttpRequest();
}
其他的
{
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
document.getElementById(“myDiv”).innerHTML=xmlhttp.responseText;
}
}
open(“GET”,“ajaxtest.html”,true);
xmlhttp.send();
}
让AJAX更改此文本
更改内容
ajaxtest.html

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.5.2/jquery-ui.min.js"></script>
<script type="text/javascript" src="http://swip.codylindley.com/jquery.DOMWindow.js"></script>

<p><a href="#inlineContent" class="defaultDOMWindow">Open DOM Window</a></p> 
<script type="text/javascript"> 
$('.defaultDOMWindow').openDOMWindow({ 
eventType:'click', 
loader:1, 
loaderImagePath:'animationProcessing.gif', 
loaderHeight:16, 
loaderWidth:17 
}); 
</script> 
<div id="inlineContent" style=" display:none;"> 
<p>Inline Content</p> 
<p>Click overlay to close window</p> 
<p>Consequat ea Investigationes in enim congue. Option velit volutpat quod blandit ex. Congue parum praesent aliquam nam clari. Qui praesent quam sollemnes id vulputate. In imperdiet diam at sequitur et. Minim delenit in dolor dolore typi. Erat delenit laoreet quinta videntur id. Ii at qui eum ut usus. Quis etiam suscipit iusto elit dolor. Dolor congue eodem adipiscing cum placerat. </p> 
<p>Erat usus lorem adipiscing non in. Nobis claram iusto et dolore facilisis. Claritatem decima velit decima ipsum wisi. Quinta ullamcorper sollemnes usus aliquip in. Ut aliquip velit tempor facit putamus. Habent duis et option quod facer. Delenit facer consequat seacula molestie notare. Qui tincidunt nobis lectores eleifend eorum. Decima usus facer id parum legere. Nonummy nonummy facilisis sit qui eodem. </p> 
</div>
function csstuff() 
{
    $('selector').css('var', 'val');
}
function domWinInit(){ 
    //include the code from 
    (http://swip.codylindley.com/jquery.DOMWindow.js)
}

function domClick(){ 
    $('.defaultDOMWindow').openDOMWindow({ 
      eventType:'click', 
      loader:1, 
      loaderImagePath:'animationProcessing.gif', 
      loaderHeight:16, 
      loaderWidth:17 
    });  
}

function csstuff() 
{
    $('selector').css('var', 'val');
}
function domWinInit(){ 
    //include the code from 
    (http://swip.codylindley.com/jquery.DOMWindow.js)
}

function domClick(){ 
    $('.defaultDOMWindow').openDOMWindow({ 
      eventType:'click', 
      loader:1, 
      loaderImagePath:'animationProcessing.gif', 
      loaderHeight:16, 
      loaderWidth:17 
    });  
}
$('.defaultDOMWindow').openDOMWindow({ 事件类型:'单击', 装载机:1, LoaderImage路径:'animationProcessing.gif', 装载机高度:16, 装载机宽度:17 }); 内联内容

function csstuff() 
{
    $('selector').css('var', 'val');
}
function domWinInit(){ 
    //include the code from 
    (http://swip.codylindley.com/jquery.DOMWindow.js)
}

function domClick(){ 
    $('.defaultDOMWindow').openDOMWindow({ 
      eventType:'click', 
      loader:1, 
      loaderImagePath:'animationProcessing.gif', 
      loaderHeight:16, 
      loaderWidth:17 
    });  
}
单击覆盖以关闭窗口

function csstuff() 
{
    $('selector').css('var', 'val');
}
function domWinInit(){ 
    //include the code from 
    (http://swip.codylindley.com/jquery.DOMWindow.js)
}

function domClick(){ 
    $('.defaultDOMWindow').openDOMWindow({ 
      eventType:'click', 
      loader:1, 
      loaderImagePath:'animationProcessing.gif', 
      loaderHeight:16, 
      loaderWidth:17 
    });  
}
enim congue的环境影响评估调查。选择一种新的、温和的方式,比如说,在南克拉里,你可以选择一种新的方式。我是一个爱哭的人。在dolore-dolore-Typic的Sequeutiur et.Minim delenit的不规则直径中。在通常情况下,第二次世界大战中的拉奥里特·昆塔·维登图尔。这是我的使命。多洛·康格是一个单身汉

function csstuff() 
{
    $('selector').css('var', 'val');
}
function domWinInit(){ 
    //include the code from 
    (http://swip.codylindley.com/jquery.DOMWindow.js)
}

function domClick(){ 
    $('.defaultDOMWindow').openDOMWindow({ 
      eventType:'click', 
      loader:1, 
      loaderImagePath:'animationProcessing.gif', 
      loaderHeight:16, 
      loaderWidth:17 
    });  
}
通常情况下,我们都不知道该怎么做。诺比斯·克拉拉姆·尤斯托和多洛尔设施。以每分钟为一分贝,以每分钟为一分贝。昆塔·乌兰科佩尔·索勒曼通常都是阿利基普。这是一张临时的脸。哈本·杜伊斯和选择权。我的脸上长满了水。这是我的荣幸。通常情况下,这是法律上的规定。不,不,不,不,不,不

function csstuff() 
{
    $('selector').css('var', 'val');
}
function domWinInit(){ 
    //include the code from 
    (http://swip.codylindley.com/jquery.DOMWindow.js)
}

function domClick(){ 
    $('.defaultDOMWindow').openDOMWindow({ 
      eventType:'click', 
      loader:1, 
      loaderImagePath:'animationProcessing.gif', 
      loaderHeight:16, 
      loaderWidth:17 
    });  
}

这就是它的工作原理

function csstuff() 
{
    $('selector').css('var', 'val');
}
function domWinInit(){ 
    //include the code from 
    (http://swip.codylindley.com/jquery.DOMWindow.js)
}

function domClick(){ 
    $('.defaultDOMWindow').openDOMWindow({ 
      eventType:'click', 
      loader:1, 
      loaderImagePath:'animationProcessing.gif', 
      loaderHeight:16, 
      loaderWidth:17 
    });  
}

就行为而言,AJAX调用不是一个浏览器窗口。它将获取ajaxtest.html并仅获取此文件。它不会尝试获取ajaxtest.html引用的任何其他文件

function csstuff() 
{
    $('selector').css('var', 'val');
}
function domWinInit(){ 
    //include the code from 
    (http://swip.codylindley.com/jquery.DOMWindow.js)
}

function domClick(){ 
    $('.defaultDOMWindow').openDOMWindow({ 
      eventType:'click', 
      loader:1, 
      loaderImagePath:'animationProcessing.gif', 
      loaderHeight:16, 
      loaderWidth:17 
    });  
}
如果要在文档中放置一些网页,请使用iframe:

<iframe id="iframe_test" src="ajaxtest.htm"></iframe>
function csstuff() 
{
    $('selector').css('var', 'val');
}
function domWinInit(){ 
    //include the code from 
    (http://swip.codylindley.com/jquery.DOMWindow.js)
}

function domClick(){ 
    $('.defaultDOMWindow').openDOMWindow({ 
      eventType:'click', 
      loader:1, 
      loaderImagePath:'animationProcessing.gif', 
      loaderHeight:16, 
      loaderWidth:17 
    });  
}

这就是它的工作原理

function csstuff() 
{
    $('selector').css('var', 'val');
}
function domWinInit(){ 
    //include the code from 
    (http://swip.codylindley.com/jquery.DOMWindow.js)
}

function domClick(){ 
    $('.defaultDOMWindow').openDOMWindow({ 
      eventType:'click', 
      loader:1, 
      loaderImagePath:'animationProcessing.gif', 
      loaderHeight:16, 
      loaderWidth:17 
    });  
}

就行为而言,AJAX调用不是一个浏览器窗口。它将获取ajaxtest.html并仅获取此文件。它不会尝试获取ajaxtest.html引用的任何其他文件

function csstuff() 
{
    $('selector').css('var', 'val');
}
function domWinInit(){ 
    //include the code from 
    (http://swip.codylindley.com/jquery.DOMWindow.js)
}

function domClick(){ 
    $('.defaultDOMWindow').openDOMWindow({ 
      eventType:'click', 
      loader:1, 
      loaderImagePath:'animationProcessing.gif', 
      loaderHeight:16, 
      loaderWidth:17 
    });  
}
如果要在文档中放置一些网页,请使用iframe:

<iframe id="iframe_test" src="ajaxtest.htm"></iframe>
function csstuff() 
{
    $('selector').css('var', 'val');
}
function domWinInit(){ 
    //include the code from 
    (http://swip.codylindley.com/jquery.DOMWindow.js)
}

function domClick(){ 
    $('.defaultDOMWindow').openDOMWindow({ 
      eventType:'click', 
      loader:1, 
      loaderImagePath:'animationProcessing.gif', 
      loaderHeight:16, 
      loaderWidth:17 
    });  
}

更正如下

document.getElementById('myDiv').innerHTML=xmlhttp.responseText;
function csstuff() 
{
    $('selector').css('var', 'val');
}
function domWinInit(){ 
    //include the code from 
    (http://swip.codylindley.com/jquery.DOMWindow.js)
}

function domClick(){ 
    $('.defaultDOMWindow').openDOMWindow({ 
      eventType:'click', 
      loader:1, 
      loaderImagePath:'animationProcessing.gif', 
      loaderHeight:16, 
      loaderWidth:17 
    });  
}
对于
getElementById

function csstuff() 
{
    $('selector').css('var', 'val');
}
function domWinInit(){ 
    //include the code from 
    (http://swip.codylindley.com/jquery.DOMWindow.js)
}

function domClick(){ 
    $('.defaultDOMWindow').openDOMWindow({ 
      eventType:'click', 
      loader:1, 
      loaderImagePath:'animationProcessing.gif', 
      loaderHeight:16, 
      loaderWidth:17 
    });  
}

窗口未打开,因为您正在动态添加DOM,所以事件不会绑定动态加载的内容。

更正如下

document.getElementById('myDiv').innerHTML=xmlhttp.responseText;
function csstuff() 
{
    $('selector').css('var', 'val');
}
function domWinInit(){ 
    //include the code from 
    (http://swip.codylindley.com/jquery.DOMWindow.js)
}

function domClick(){ 
    $('.defaultDOMWindow').openDOMWindow({ 
      eventType:'click', 
      loader:1, 
      loaderImagePath:'animationProcessing.gif', 
      loaderHeight:16, 
      loaderWidth:17 
    });  
}
对于
getElementById

function csstuff() 
{
    $('selector').css('var', 'val');
}
function domWinInit(){ 
    //include the code from 
    (http://swip.codylindley.com/jquery.DOMWindow.js)
}

function domClick(){ 
    $('.defaultDOMWindow').openDOMWindow({ 
      eventType:'click', 
      loader:1, 
      loaderImagePath:'animationProcessing.gif', 
      loaderHeight:16, 
      loaderWidth:17 
    });  
}

窗口未打开,因为您正在动态添加DOM,所以事件不会绑定到动态加载的内容。

我终于找到了解决方案。

function csstuff() 
{
    $('selector').css('var', 'val');
}
function domWinInit(){ 
    //include the code from 
    (http://swip.codylindley.com/jquery.DOMWindow.js)
}

function domClick(){ 
    $('.defaultDOMWindow').openDOMWindow({ 
      eventType:'click', 
      loader:1, 
      loaderImagePath:'animationProcessing.gif', 
      loaderHeight:16, 
      loaderWidth:17 
    });  
}
//用于在HTML响应后触发CSS

function csstuff() 
{
    $('selector').css('var', 'val');
}
function domWinInit(){ 
    //include the code from 
    (http://swip.codylindley.com/jquery.DOMWindow.js)
}

function domClick(){ 
    $('.defaultDOMWindow').openDOMWindow({ 
      eventType:'click', 
      loader:1, 
      loaderImagePath:'animationProcessing.gif', 
      loaderHeight:16, 
      loaderWidth:17 
    });  
}
//用于在HTML响应后触发JavaScript

function csstuff() 
{
    $('selector').css('var', 'val');
}
function domWinInit(){ 
    //include the code from 
    (http://swip.codylindley.com/jquery.DOMWindow.js)
}

function domClick(){ 
    $('.defaultDOMWindow').openDOMWindow({ 
      eventType:'click', 
      loader:1, 
      loaderImagePath:'animationProcessing.gif', 
      loaderHeight:16, 
      loaderWidth:17 
    });  
}
成功的例子是当status==200且readyState==4时,在插入HTML响应后启动js&css函数

function csstuff() 
{
    $('selector').css('var', 'val');
}
function domWinInit(){ 
    //include the code from 
    (http://swip.codylindley.com/jquery.DOMWindow.js)
}

function domClick(){ 
    $('.defaultDOMWindow').openDOMWindow({ 
      eventType:'click', 
      loader:1, 
      loaderImagePath:'animationProcessing.gif', 
      loaderHeight:16, 
      loaderWidth:17 
    });  
}
xmlhttp.onreadystatechange=function()
{
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
        document.getElementById('myDiv').innerHTML=xmlhttp.responseText;

        // CSS & JavaScript firing goes here
        csstuff();
        domWinInit();
        domClick();
    }
}

感谢您的重播。

我终于找到了解决方案。

function csstuff() 
{
    $('selector').css('var', 'val');
}
function domWinInit(){ 
    //include the code from 
    (http://swip.codylindley.com/jquery.DOMWindow.js)
}

function domClick(){ 
    $('.defaultDOMWindow').openDOMWindow({ 
      eventType:'click', 
      loader:1, 
      loaderImagePath:'animationProcessing.gif', 
      loaderHeight:16, 
      loaderWidth:17 
    });  
}
//用于在HTML响应后触发CSS

function csstuff() 
{
    $('selector').css('var', 'val');
}
function domWinInit(){ 
    //include the code from 
    (http://swip.codylindley.com/jquery.DOMWindow.js)
}

function domClick(){ 
    $('.defaultDOMWindow').openDOMWindow({ 
      eventType:'click', 
      loader:1, 
      loaderImagePath:'animationProcessing.gif', 
      loaderHeight:16, 
      loaderWidth:17 
    });  
}
//用于在HTML响应后触发JavaScript

function csstuff() 
{
    $('selector').css('var', 'val');
}
function domWinInit(){ 
    //include the code from 
    (http://swip.codylindley.com/jquery.DOMWindow.js)
}

function domClick(){ 
    $('.defaultDOMWindow').openDOMWindow({ 
      eventType:'click', 
      loader:1, 
      loaderImagePath:'animationProcessing.gif', 
      loaderHeight:16, 
      loaderWidth:17 
    });  
}
成功的例子是当status==200且readyState==4时,在插入HTML响应后启动js&css函数

function csstuff() 
{
    $('selector').css('var', 'val');
}
function domWinInit(){ 
    //include the code from 
    (http://swip.codylindley.com/jquery.DOMWindow.js)
}

function domClick(){ 
    $('.defaultDOMWindow').openDOMWindow({ 
      eventType:'click', 
      loader:1, 
      loaderImagePath:'animationProcessing.gif', 
      loaderHeight:16, 
      loaderWidth:17 
    });  
}
xmlhttp.onreadystatechange=function()
{
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
        document.getElementById('myDiv').innerHTML=xmlhttp.responseText;

        // CSS & JavaScript firing goes here
        csstuff();
        domWinInit();
        domClick();
    }
}


谢谢你的重播。

你也能给我们看看ajaxtest.html代码吗?@DevangRathod ajaxtest.html包括在内//你的css代码在ajaxtest.html中的哪里?@DevangRathod JS也不工作!当您单击Open DOM Window时,它是否会打开窗口?您是否也可以向我们显示ajaxtest.html代码?@DevangRathod ajaxtest.html包括在内//您的css代码在ajaxtest.html中的哪里?@DevangRathod JS也不工作!当您单击“打开DOM窗口”时,它是否将打开窗口?“它将获取ajaxtest.html,并且仅获取此文件”不真实将获取哪些其他文件?From:“它提供了一种在URL上检索数据的简便方法。”“它将获取ajaxtest.html,并且仅此文件”不真实“将获取哪些其他文件?”?From:“它提供了一种在URL上检索数据的简单方法。”。那么,我应该怎么做才能动态加载带有事件的内容呢!现在我也无能为力,因为我没有进一步的想法。但是,如果我能找到解决方案,即使我也会尽力帮助你。那么,我应该怎么做才能动态加载带有事件的内容呢!现在我也无能为力,因为我没有进一步的想法。但即使是我也会尽力帮助你,如果我能找到解决办法的话。
function csstuff() 
{
    $('selector').css('var', 'val');
}
function domWinInit(){ 
    //include the code from 
    (http://swip.codylindley.com/jquery.DOMWindow.js)
}

function domClick(){ 
    $('.defaultDOMWindow').openDOMWindow({ 
      eventType:'click', 
      loader:1, 
      loaderImagePath:'animationProcessing.gif', 
      loaderHeight:16, 
      loaderWidth:17 
    });  
}