2014-01-24 45 views
2

好的我從一開始就重新發布。我對此感到沮喪,因爲我即將放棄JQM。這不應該這麼難。返回Jquery站點的主頁時無法訪問腳本

我的網站結構:

OUI/ 
index.php 
js/ 
pages/ 
images/ 

在我的index.php頁面我剛一二線形式登錄我在http://localhost/~me/OUI/

<? session_start(); 
?><!DOCTYPE HTML> 
<html> 
<head> 
<meta name="viewport" content="width=device-width, user-scalable=false,initial-scale=1;"> 
<meta name="apple-mobile-web-app-capable" content="yes"> 

<link rel="stylesheet" href="js/jquery.mobile-1.4.0.min.css"> 
<link rel="stylesheet" type="text/css" href="css/jqm-datebox.min.css" /> 
<script src="js/jquery-1.10.2.min.js" type="text/javascript"></script> 
<script src="js/jquery.mobile-1.4.0.min.js" type="text/javascript"></script> 

<script type="text/javascript" src="js/jqm-datebox.comp.datebox.min.js"></script> 

<script src="js/mainsite.js" type="text/javascript"></script> 


<link rel="stylesheet" href="css/main.css"> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
<title>OUI CHEF</title> 

</head> 

<body style="background-image:url(media/kitchen.jpg)"> 


    <div data-role="page" id="loginarea"> 

    <div data-role="content" id="maincontentarea2"> 
    <img src="media/OUIChef.png" style="margin-top:75px" id="mainimage"> 

    <div data-role="fieldcontain" class="ui-hide-label"> 
    <label for="username">Username:</label> 
    <input type="text" name="username" id="username" value="" style="text-align:center" placeholder="Username"/><BR> 
<label for="username">Password:</label> 
    <input type="password" name="password" id="password" value="" style="text-align:center" placeholder="Password"/> 
</div> 
    <div style="text-align:center"> 
    <a href="javascript:doLogin();" data-role="button" data-inline="true" data-mini="true">DO LOGIN</a> 
</div> 

</div><!-- /page --> 
</div> 
</body> 
</html> 

所以,當我打的登錄按鈕它帶我到我的options.php頁面vi以下功能:

function doLogin(){ 

$.ajax({ 
    type: "POST", 
    url: "functions/checklogin.php", 
    data: { 
     usrnm: $('#username').val() , passwd: $('#password').val() 
     } 
}) 
    .done(function(msg) { 
    if(msg.match(/YES/)){ 
     $('#username').val(''); 
      $('#password').val(''); 

     $("body").pagecontainer("change","pages/options.php",{ }); 
    } 
    else 
    { 
    alert(msg); 
    } 

    }); 

} 

在URL欄中我現在有http://localhost/~me/OUI/pages/options.php和頁面上的任何東西都運行良好。我有登出按鈕。在代碼中調用該

OPTIONS.PHP:

<div data-role="page" id="optionspage">  
<div data-role="header"> 
<a href="javascript:doSignout();" data-role="button" data-mini="true" class="ui-btn-right" style="padding:5px">Sign Out</a> 

    <h1>MAIN</h1> 
</div> 

    <div data-role="content" id="options1"> 
    <? if($_SESSION['role']=='A'){?> 
     <a href="admin.php" data-role="button" data-mini="true">ADMIN PAGE</a> 
     <a href="ordersetup.php" data-role="button" data-mini="true">ORDER SETUP PAGE</a> 
     <? } ?> 
     <a href="production.php" data-role="button" data-mini="true">PRODUCTION</a> 
     <a href="menurecipe.php" data-role="button" data-mini="true">MENU/RECIPE PAGE</a> 


    </div><!-- /content --> 
    </div> 

這個調用JS:

function doSignout(){ 
$.ajax({ 
    type: "POST", 
    url: "../functions/signout.php", 
    data: { } 
}) 
    .done(function(msg) { 
     $('body').pagecontainer("change", "#loginarea",{}); 

    }); 
} 

我永遠無法得到的鏈接signout頁面正確鏈接。如果我把雙點應該是正確的,從「頁」文件夾中,我得到它試圖鏈接到

http://localhost/~me/functions/signout.php 

,如果我去掉雙點我得到

http://localhost/~me/OUI/pages/functions/signout.php 

這兩者都是404錯誤.......這是我的書中的BUNK。 「..」實際上是刪除兩個目錄..不只一個。

發生了什麼事? PLease幫助

+0

如果登錄腳本失敗,爲什麼你沒有提供該代碼? –

+0

它不是登錄腳本。一旦我運行doSignout Javascript,就可以訪問任何東西。就好像Jquery移動失去了AJAX加載任何東西的能力。 – BostonMacOSX

+0

退房http://stackoverflow.com/questions/19174611/how-to-change-page-in-latest-jquery-mobile-1-4-beta – user583576

回答

0

由於我們沒有看到您登錄功能,我假設它看起來像下面這樣?

$.ajax({ 
    type: "POST", 
    url: "../functions/signin.php", 
    data: {} 
}) 

如果是如何找到它的標誌,當你居住於/OUI/開始—當然,當您在您的主頁也將需要"functions/signin.php"的情況。

簡而言之,我猜你的登錄代碼在最初的主頁上是不同的,然後在通過ajax加載後續頁面後,您的登錄代碼被設計爲與"../"一起使用的代碼覆蓋或修改在更深的頁面上加上前綴......並且當您切換回主頁時,這不會被糾正。

基本上你需要重寫代碼來檢測當前URL的深度有多少個文件夾,並相應地請求你的ajax文件......或者設置一個保持完整域路徑的全局變量(這很容易更新)爲所有ajax網址加上前綴。即:

var ROOT_URL = 'http://localhost/OUI/'; 

根據您要使用這條道路有什麼可以通過PHP或JavaScript生成,PHP是更可靠—作爲最終用戶不需要JavaScript —但託管落後時,它可以混爲一談代理和共享主機。

var ROOT_URL = 'http://<?php echo $_SERVER["HTTP_HOST"]; ?>/OUI/'; 

var ROOT_URL = 'http://' + window.location.host + '/OUI/';