您的位置:首页 > Web前端 > JavaScript

JS 清除IE缓存 以及 session id的传递

2013-10-18 20:24 351 查看

ajax session id的传递

使用ajax传递的php页面,不能获取到其他普通php页面的session,原因是使用ajax传递过后的页面的session id发生了变化,应该将session id做为参数传递过去。

设置一个参数:

$sid = 123;

$session_id = md5($sid);

session_id($session_id);

session_start();

$sessid = session_id(); //获取当前的session的session id

在前一页获取session id,然后作为参数传到下一个页面,在session_start()前面加session_id(传过来的 session id);

就是在前一页取得session id,然后想办法传递到下一页,在下一页的session_start();代码之前加代码session_id

JS 清除IE缓存

转自这位仁兄的文章: http://blog.csdn.net/seng3018/article/details/5889894
对于动态文件,比如 index.asp?id=... 或者 index.aspx?id=... 相信有经验的程序员都知道怎样禁止浏览器缓存数据了.

但是对于静态文件(css,jpg,gif等等), 在什么场合下面我们需要禁止浏览器缓存他们,怎么做?

方法一:Dojo中我们可以用简单的方法完成:在dojo.xhrGet(包括post)等方法中都包含preventCache属性,此属性的含义: “默认为启用浏览器缓存,否则将通过自动增加不同的参数来确保浏览器缓存失效” 我们只要把此属性赋值为:“true”即可。

方法二:document.write("

其中 ver=113 的 113就是版本号,一般都是采用 CVS 或其他工具生成的开发版本号。

这样真正做到了应该缓存的时候缓存静态文件,当版本有更新的时候从获取最新的版本,并更新缓存。

对于图像 来有效利用和更新缓存.

js清除浏览器缓存 二

为了减小浏览器与服务器之间网络传输压力,往往对静态文件,如js,css,修饰的图片做cache,也就是给这些文件的HTTP响应头加入 Expires和Cache-Control参数,并指定缓存时间,这样一定时间内浏览器就不会给服务器发出任何的HTTP请求(除了强制刷新),即使在 这段时间内服务器的js或css或图片文件已经更新多次,但浏览器的数据依然是原来最能初cache的旧数据,有没有办法让浏览器拿到已经修改后的最新数 据呢?

有,方法是用ajax请求服务器最新文件,并加上请求头If-Modified-Since和Cache-Control,如下:

$.ajax({

type: "GET",

url: "static/cache.js",

dataType: "text",

beforeSend :function(xmlHttp){

xmlHttp.setRequestHeader("If-Modified-Since","0");

xmlHttp.setRequestHeader("Cache-Control","no-cache");

}

});

这里用了jquery.

//cache:false,

//ifModified:true,

/*beforeSend :function(xmlHttp){

xmlHttp.setRequestHeader("If-Modified-Since","0");

xmlHttp.setRequestHeader("Cache-Control","no-cache");

},*/

这样浏览器就会把最新的文件替换掉本地旧文件。

当然,这里还一个问题就是js必须知道服务器更新了那个js、css、图片,利用cookie和时间版本应该可以解决.

jquery自从1.2开始就有ifModified和cache参数了,不用自己加header

ifModified Boolean Default: false

Allow the request to be successful only if the response has changed since the last request. This is done by checking the Last-Modified header. Default value is false, ignoring the header.

cache Boolean Default: true

Added in jQuery 1.2, if set to false it will force the pages that you request to not be cached by the browser.

$.ajax({

type: "GET",

url: "static/cache.js",

dataType: "text",

cache:false,

ifModified :true

});

代码

// 转化货币     beforeSend 里面的代码 禁止浏览器缓存  这是之前 的 ie 没有执行ajax.  没有刷新的原因。  带随机的时间数Math.random()就解决了问题
function  setIl8n(currency,reload){
//$$(region).find("div").text()
$$.ajax({
type: "GET",
url: "g5_cmd.php",
data: "act=set_il8n¤cy="+currency+"&t="+Math.random(),

dataType:'TEXT',
//beforeSend :function(xmlHttp){
//	xmlHttp.setRequestHeader("If-Modified-Since","0");
//	xmlHttp.setRequestHeader("Cache-Control","no-cache");
},
success: setIl8nResponse
});

if(reload==0){
alert('set successfully.');
location.reload();
}
}

/* *
* 处理货币的反馈信息
*/
function setIl8nResponse(result)
{
$$("#il8n").find("p").text("Currency:"+result);
}


php实时汇率

​function getExchangeRate($from_Currency,$to_Currency)

{

$amount = urlencode($amount);

$from_Currency = urlencode($from_Currency);

$to_Currency = urlencode($to_Currency);

$url = "download.finance.yahoo.com/d/quotes.html?s=".$from_Currency.$to_Currency."=X&f=sl1d1t1ba&e=.html";

$ch = curl_init();

$timeout = 0;

curl_setopt ($ch, CURLOPT_URL, $url);

curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");

curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

$rawdata = curl_exec($ch);

curl_close($ch);

$data = explode(',', $rawdata);

return $data[1];

}

​//调用方法

echo getExchangeRate("CNY","USD");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: