2012-11-04 83 views
0

我有一個註銷功能,在使用chrome時可以正確啓動。但是用Firefox,它並沒有。從我在Firefox中可以看出,foo.setAttribute("action", "../index.php");沒有發生,因爲它在Chrome中正確無誤。它令我難以置信,因爲我無法真正在Firebug中調試這部分。從JavaScript註銷程序PHP和JavaScript - 「註銷」代碼適用於Chrome,但不適用於Firefox

<?php 
require_once('/lock_down/php/db_login.php'); 
require_once('/lock_down/php/authenticate.php'); 

if (isset($_POST['action'])) { 
    $action = $_POST['action']; 
} else { 
    $action = 'first_time'; 
} 

switch($action) { 
case 'first_time': 
    include('/lock_down/login.html'); 
    break; 
case 'login' : 
    $username = $_POST['uname']; 
    $password = $_POST['pword']; 
    if (http_login($username, $password)) { 
     include('/lock_down/file_server.html'); 
    } else { 
     include('/lock_down/login.html'); 
    } 
    break; 

case 'logoff' : 
    $_POST = array(); 
    echo "logged off"; 
    include('/lock_down/login.html'); 
    break; 

default: 
// include('/lock_down/php/login.php'); 
    break; 


} 

?> 

摘自file_server.html

 case "logoutButton": 
     var form = document.createElement("form"); 
     var foo = document.createElement("input"); 
     foo.setAttribute("method", "post"); 
     foo.setAttribute("type", "hidden"); 
     foo.setAttribute("action", "../index.php"); 
     foo.setAttribute("name", "action"); 
     foo.setAttribute("value", "logoff"); 
     form.appendChild(foo); 
     form.submit(); 
     break; 

同樣,所有的這部作品在鉻。但在Firefox中,它不會註銷並加載../index.php

+0

爲什麼不使用GET? –

回答

3

要設置形式methodaction輸入元素上,而不是表單元素

foo.setAttribute("method", "post"); 

應該

form.setAttribute("method", "post"); 

編輯:不知道,如果一個形式,是不是在DOM將在所有瀏覽器中提交,也可能需要附加。您可以使用重定向成功回調而不是創建表單的ajax請求

+0

謝謝,很好的瞭解錯誤的setAttributes!然而,根本原因是從你的編輯....因爲它沒有被添加到DOM它不會在Firefox中提交。我猜Chrome不關心。謝謝! – dman

相關問題