2012-09-23 2 views

답변

0

모든 것이 '배경 화면'에서 발생하기 때문에 혼란 스러울 수 있습니다. 다른 Javascript처럼 페이지를로드하는 브라우저가 AJAX 코드를 실행하는 브라우저라는 것을 알았습니다. 또한 브라우저의 동일한 인스턴스는 세션을 사용할 수도 있음을 의미합니다.


나는이 결론에 도달하기 위해 약간의 코드를 실행했다. 다음 예제는 기존 ASP에 있습니다. AJAXly 호출에 마침내

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

, 하나 개의 파일 :

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

다음, 하나 개의 파일이 그들 (디스플레이 결과를) 읽을 수 :

첫째로, 나는 이러한 변수를 작성 하나 개의 파일이 그들 :

<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: 

그래서 당신이 그것을 가지고 :)

관련 문제