2013-04-05 98 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>標籤。