2012-05-17 45 views
2

如果我的文件位於不同文件夾中,如何使用.loadJquery.load來自不同文件夾的URL

我曾嘗試:

$("#messageWindow").load("http://localhost/MainFolder/Messanging/index.php"); 
$("#messageWindow").load("Messanging/index.php"); 
$("#messageWindow").load("../Messanging/index.php");  

實在不行,我一直在使用的URL,但我似乎無法讓自己的答案上班的時候讀到different folders話題。

謝謝。

好的,我已經修復了問題The 1st and 2nd URL above WORKS但我有另一個問題。 index.php有大量的網址。

<script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script> 
<script src="../plugins/ui/jquery.ui.core.js"></script> 
<script src="../plugins/ui/jquery.ui.widget.js"></script> 
<script src="../plugins/ui/jquery.ui.datepicker.js"></script> 
<script src="../plugins/timezone/jstz.min.js"></script> 
<script type="text/javascript" src="file_js/index.js"></script> 

但現在這些URLS不再工作,我採取的解決方案是添加整個URL。

<script type="text/javascript" src="http://localhost/MainFolder/js/jquery-1.7.2.min.js"></script> 
<script src="http://localhost/MainFolder/plugins/ui/jquery.ui.core.js"></script> 
<script src="http://localhost/MainFolder/plugins/ui/jquery.ui.widget.js"></script> 
<script src="http://localhost/MainFolder/plugins/ui/jquery.ui.datepicker.js"></script> 
<script src="http://localhost/MainFolder/plugins/timezone/jstz.min.js"></script> 
<script type="text/javascript" src="http://localhost/MainFolder/Messanging/file_js/index.js"></script> 

這是一個喧囂,如果我上傳文件到我的虛擬主機。我認爲使用相對路徑會做到這一點,但我不知道它是如何工作的。

+3

你在'console' \ firebug'中看到了什麼? – gdoron

+1

Messanging?可能是消息傳遞 –

+1

我認爲你需要提供進一步的細節。首先,瀏覽器的網址是否工作(「http://localhost/MainFolder/Messanging/index.php」)?其次,你是否嘗試過使用同一個文件夾中的網址?還有一件事是:「Messanging」拼寫爲文件夾的名稱? (對不起,如果最後一個看起來有點愚蠢,但我已經做了很多這樣的錯誤:D) – Mircea

回答

0

對於jQuery load(),您可以包含當前頁面的相對路徑或絕對路徑。如果你在JS控制檯或螢火蟲中運行下面的命令,你應該在瀏覽器中看到相同的問題兩次。

$("#header").load("https://stackoverflow.com/questions/10643503/jquery-load-url-from-different-folder"); 

內容也需要來自同一產地的原始頁面(你只能從同一個域加載內容)。

+1

我們可以使用'load'方法的相對路徑和絕對路徑 – pomeh

+0

@pomeh - 感謝您的更正! – SliverNinja

相關問題