URL pulito e javascript problema ordine di caricamento in php
-
27-10-2019 - |
Domanda
Sto cercando di costruire un webpage.packing.php php contiene:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="description" content="Fresh Sliding Thumbnails Gallery with jQuery and PHP" />
<meta name="keywords" content="jquery, images, gallery, full page, thumbnails, scrolling, sliding, php, xml"/>
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen"/>
<link rel="stylesheet" type="text/css" href="css/ddsmoothmenu.css" />
<script type="text/javascript" src="js/jquery-1.6.1.js"></script>
<link rel="stylesheet" type="text/css" href="css/site.css" />
<script type="text/javascript" src="js/ddsmoothmenu.js">
</script>
<script type="text/javascript" src="js/jquery.gallery.js"></script>
<script type="text/javascript" >
$(document).ready( function(){
// Menu
ddsmoothmenu.init({
mainmenuid: "smoothmenu1", //menu DIV id
orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
classname: 'ddsmoothmenu', //class added to menu's outer DIV
//customtheme: ["#1c5a80", "#18374a"],
contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
});
});
</script>
e il mio .htaccess è
RewriteEngine On
RewriteRule ^packing/Pure packing.php?id=pure
RewriteRule ^packing/ExtraVirgin packing.php?id=EV
Ora, quando apro il mio php che dire rendersproperly ho packing.php aperto
Ma quando ho aperto utilizzando l'URL pulito dà un errore in Firebug affermando $ non è definito.
Ora so che il problema è dovuto al l'ordine di caricamento sbagliato di javascript. Perché accade e come posso risolverlo?
Grazie.
Soluzione
Quando si utilizzano gli URL pulite, il browser pensa che sia in una directory diversa (/packing/pure
). I relativi URL che puntano ai file JS non funzionerà più.
Utilizzare URL assoluti invece:
<script type="text/javascript" src="/js/jquery.gallery.js">
Altri suggerimenti
Ci potrebbe essere un problema con i percorsi? Non stai dando il percorso di, ma stai cambiando percorsi dalla radice (packing.php
) ad un 2 ° livello (packing/Pure
). Probabilmente è alla ricerca per i file .js nel percorso sbagliato, come packing/js/
invece di /js
.
Provare a utilizzare percorsi assoluti per il vostro carico:
<script type="text/javascript" src="/js/jquery-1.6.1.js"></script>
(avviso la barra!)
o anche
<script type="text/javascript" src="http://yoursite.com/js/jquery-1.6.1.js"></script>