2011-12-19 66 views
1

我有一個jquery/AJAX登錄頁面,可以在除Chrome以外的所有瀏覽器中完美工作。看起來我遇到了Chrome上的一個問題,其覆蓋範圍爲Problems with jQuery getJSON using local files in Chrome - 有人說這是一個錯誤,其他人說這是一個很好的安全性。我說這是令人沮喪的。鉻和 - 允許文件訪問從文件

我應該補充一點,登錄實際上工作,這是AJAXiness打破。解決方案是將- 允許文件從文件訪問添加到啓動環境。很好,但是如何解決使用Chrome瀏覽器的網站訪問者的問題?

作爲Chrome用戶,必須編寫代碼來檢查Chrome用戶並說「使用其他內容」會很諷刺。

有沒有人有任何想法來解決這個問題是可能的?

對於什麼是值得的,這裏是代碼:

$(document).ready(function() 
{ 
    $("#login_form").submit(function() 
    { 
     //remove all the class add the messagebox classes and start fading 
     $("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn(1000); 
     //check the username exists or not from ajax 
     $.post("/ajaxsignin.php",{email:$('#email').val(), password:$('#password').val(), remember:$('#remember').val(), rand:Math.random()} ,function(data) 
     { 
      if(data.success) //if correct login detail 
      { 
///////////////////////////////////////////////////////////////////// 
// if I put an alert() here, Chrome just doesn't see it but all other browsers do 
////////////////////////////////////////////////////////////////////// 

       document.getElementById("msgbox").innerHTML='Sign in successful'; 

       document.getElementById("topmenutext").style.paddingTop='3px'; 

       document.getElementById("topmenutext").innerHTML="BUG REPORT    |sign out|contact|help"; 

       var sPath = window.location.pathname; 
       var sPage = sPath.substring(sPath.lastIndexOf('/') + 1); 

       if(sPage == "register.php" || sPage == "index.php" || sPage == ""){ 
        window.location.href='menu.php'; 
       } 
       else{ 
        disablePopup(); 
       } 

      } 
      else //if login failed 
      { 
       $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox 
      { 
       //add message and change the class of the box and start fading 
       $(this).html('Login failed - perhaps you need to register for an account').addClass('messageboxerror').fadeTo(900,1); 
      });  
      } 

     },"json"); 
     return false; //not to post the form physically 
    }); 
    //now call the ajax also focus move from 
    $("#submitbtn").click(function() 
    { 
     $("#login_form").trigger('submit'); 
    }); 
});

回答

1

這應該只,如果你要使用Chrome瀏覽器從本地文件系統加載的文件有問題。這是因爲Chrome在文件系統上具有瘋狂限制性的AJAX策略。

本質上,Chrome不允許AJAX請求到HTML頁面文件夾以外的文件。要解決這個問題,只需從Web服務器提供文件。您的網站訪問者可能會通過網絡服務器訪問您的網站,因此這對他們來說應該不成問題。

相關問題