2012-06-03 42 views
0

我有一个使用Jetpack构建器创建的Firefox扩展。Firefox扩展 - 使用XMLHttpRequest不起作用的cookie访问

会发生什么,我在页面上设置了用户登录的cookie(PHP)。 cookie的内容是一个用于识别用户的特殊密钥,该密钥可以获得用户的某些信息,以便插件工作。

我将Firefox插件中的XMLHttpRequest制作成与登录页面相同的服务器上的PHP页面。这个页面必须读取cookie,并根据它来检索数据。

问题是,cookie没有被php页面读取。整个过程在Chrome中运行,但不在FF中。这个问题不应该是跨域的,因为访问cookie的PHP页面与Login PHP设置cookie的域名在同一个域中。

请帮忙...谢谢! :)

P.S.这是我的XMLHttpRequest:

function getData() { 
       client = new XMLHttpRequest(); 
       try{ 
        //SHOULD I INCLUDE THE CODE IN 'TRY' IN HERE? 
        client.open('GET','https://www.istyla.com/Popup/themes.php');     
       } catch (e){ 
        alert("error while opening " + e.message); 
       } 

       client.onreadystatechange = function(){ 
        if (client.readyState ==4){ 
          user_data = client.responseText; 
          if(document.domain == "facebook.com"  || document.domain == "www.facebook.com") { 
           addCSS(user_data); 
          } 
        } 
       } 

       client.send(null); 
} getData(); 

回答

0

你可以尝试发送之前将此代码添加到您的要求(从https://addons.mozilla.org/sl/firefox/files/browse/134669/file/modules/sendtophone.js#L173复制)。

// To send correctly cookies. 
// Force the request to include cookies even though this chrome code 
// is seen as a third-party, so the server knows the user for which we are 
// requesting favorites (or anything else user-specific in the future). 
// This only works in Firefox 3.6; in Firefox 3.5 the request will instead 
// fail to send cookies if the user has disabled third-party cookies. 
try { 
    req.channel.QueryInterface(Ci.nsIHttpChannelInternal). 
    forceAllowThirdPartyCookie = true; 
} 
catch(ex) { /* user is using Firefox 3.5 */ } 
+0

这段代码究竟做了什么? –

+0

我在我的问题中包含了我的XMLHttpRequest。我在哪里放这个代码?此代码是否允许XMLHttpRequest函数作为正在浏览的实际页面(即它可以访问Cookie)? –