2013-04-05 73 views
0

我搜索了互联网,直到我去了蓝色,但无法弄清楚,为什么它不工作。jQuery AJAX奋斗

我有JavaScript,但这只是为Firefox工作。没有其他浏览器。

所以,我决定去jQuery。

我想要做的是这样的: - 我有一个文件夹。 - 在这个文件夹中,我有一个html.html文件。这是我的主要网站。 - 然后我有一个文件home.html。

中将Html.HTML看起来是这样的:

<html> 
    <head> 
     <title> 
      Struggeling with jQuery ajax! ******* 
     </title> 
    </head> 
    <body> 
     <div="one"> 
      Load the page here 
     </div> 
    </body> 
</html> 

和home.html的是这样的:

<html> 
     <head> 

     </head> 
     <body> 
      Please load this into the div! (this text will be displayed in other words) 
     </body> 
    </html> 

如何在地球上我能得到这个使用jQuery?请帮帮我。我无法做到这一点。

============================================== =======================================

好吧,所以这是如何看起来像现在。在我的文件,我的Home.html:

<html> 
    <head> 
     <title> 
      Struggeling with jQuery ajax! ******* 
     </title> 
     <script language="javascript" src="jQuery.js"></script> 
     <script> 
      $(document).ready(function() { 
       $("#one").load("html.html body"); 
      }); 
     </script> 
    </head> 
    <body> 
     <div id="one"> 
      Load the page here 
     </div> 
    </body> 
</html> 

我下载的jQuery的开发版本,这是一个文件,其中home.html的所在(的jquery.js)。

然后在其他中将Html.HTML看起来是这样的:

<html> 
    <head> 

    </head> 
    <body> 
     Please load this into the div! (this text will be displayed in other words) 
    </body> 
</html> 

,但是这是行不通的。我不明白“请这个加载到DIV!(这几个字换句话说显示)”

+0

我相信你可以在jQuery中使用'.load()'函数。 – tymeJV 2013-04-05 20:32:44

+0

所以你有JavaScript,你已经搜索,决定去与jQuery,仍然没有代码发布? – adeneo 2013-04-05 20:35:42

回答

2

试试这个jQuery

<script> 
$(document).ready(function() { 
    $("#one").load("home.html body"); 
}); 
</script> 

此外,更新中将Html.HTML(我不喜欢这个名字,顺便说一下,使用index.html为主页)目标div ID。

<div id="one"></div> 

编辑:我也没有看到你引用你的jQuery库的地方,一定要这样做!

+0

还需要更新html.html以使div id =“one”not div =“one”。 – scottheckel 2013-04-05 20:35:18

+0

哈哈,我刚刚看到了,很好。 – tymeJV 2013-04-05 20:35:50

+0

我对我发表了一篇文章。请参见。我没有明白。它不工作。 – 2013-04-05 21:06:15

0

首先给你的div一个正确的ID。

<div id="one"> 
    Load the page here 
</div> 

然后使用jQuery获取和加载,使用jQuery.load()函数。

$('#one').load('folder/html.html', function() { 
    alert('Load was performed.'); 
}); 

还删除任何“加倍”标签。换句话说,当你插入html.html你不想:

<div id="one"> 
    <html> 
      <body> 
       Stuff 
      </body> 
    </html> 
</div> 

它会很难看,可能会引起问题。因此删除那些额外的<html><body>标签。