2012-09-23 40 views
0

当我通过AJAX调用URL时,它读取了哪些cookie?会议也一样。谁从AJAX调用中获取cookie?

谁实际运行线程?它是我的默认系统浏览器,当前的,还是其他实体?

回答

0

这可能会令人困惑,因为这一切都发生在“幕后”。我发现,像其他任何Javascript一样,加载页面的浏览器是运行AJAX代码的浏览器。而且 - 浏览器的同一个实例,也就是说会话也可以使用。


我已经运行了一段代码来得出这个结论。以下示例采用传统ASP。

首先,我有一个文件,其中写道:这些变量:

Response.Cookies("testing") = "One, Two, Three" 
Session("testing") = "Forty One, Forty Two, Forty Three" 

接下来,一个文件的读取他们(和显示结果):

Cookie is: 
<% 
Response.Write Request.Cookies("testing") 
%> 
<br> 
Session is: 
<% 
Response.Write Session("testing") 
%> 

最后一个文件AJAXly通话他们:

<div id="result"></div> 
<script type="text/javascript"> 
//Different browsers initiate ajax differently 
try {var oXH = eval("new Active"+"X"+"Object('MSXML2.XMLHTTP')");} 
catch(e) {var oXH = new XMLHttpRequest();} 

//Call page that reads the cookie 
oXH.open("GET","/testCookie.asp",true); 
oXH.onreadystatechange = function(){ 
    if ((oXH.readyState != 4)||(oXH.status != 200)) 
     return true; 
    else 
    { 
     document.getElementById("result").innerHTML = oXH.responseText; 
    } 
}; 
oXH.send(null); 
</script> 

在一个浏览器上运行第一个文件,最后一个在几个,第一个显示:

Cookie is: One, Two, Three 
Session is: Forty One, Forty Two, Forty Three 

其余显示:

Cookie is: 
Session is: 

所以你有它:)