最近做个小东西用到jquery的ajax
由于要从站外获取数据 也就是这个地址http://hq.sinajs.cn/list=sz002004(没办法对华邦制药有点感觉- -!)
先是编码问题 sina用的gb2312就不说了
结果我写ajax的时候 咋就请求的不对呢
$.ajax({ type:"GET", url:"http://hq.sinajs.cn/list=sz002004", dataType:"script", success:function(data){ alert('hq_str_sz002004'); } });
用firebug调试 url老是后面_?再加上一堆数字
结果自然也就获取不到了,问了一堆人终于解决了 在选项里加上cache就行了
这可能是由于防止js文件的缓存把,以后更新网站时也能用用 xxx.js?version=timestamp

最后找到jq源码 贴上 1.4.4版5829行
if ( s.dataType === "script" && s.cache === null ) { s.cache = false; } if ( s.cache === false && noContent ) { var ts = jQuery.now(); // try replacing _= if it is there var ret = s.url.replace(rts, "$1_=" + ts); // if nothing was replaced, add timestamp to the end s.url = ret + ((ret === s.url) ? (rquery.test(s.url) ? "&" : "?") + "_=" + ts : ""); }
看来以后还得多看看源码啊 完全搞懂这些框架

第一次发帖 呵呵 不知道效果啥样
1 楼
solidco2
2011-02-17
回个帖鼓励下
2 楼
wxiong1984
2012-08-20
我也碰到这个问题,也没弄出来,请赐教。 在什么地方加 cache啊?