最近做个小东西用到jquery的ajax
由于要从站外获取数据 也就是这个地址[url]http://hq.sinajs.cn/list=sz002004[/url](没办法对华邦制药有点感觉- -!)
先是编码问题 sina用的gb2312就不说了
结果我写ajax的时候 咋就请求的不对呢
用firebug调试 url老是后面_?再加上一堆数字
结果自然也就获取不到了,问了一堆人终于解决了 在选项里加上cache就行了
这可能是由于防止js文件的缓存把,以后更新网站时也能用用 xxx.js?version=timestamp :D
最后找到jq源码 贴上 1.4.4版5829行
看来以后还得多看看源码啊 完全搞懂这些框架 :idea:
第一次发帖 呵呵 不知道效果啥样
由于要从站外获取数据 也就是这个地址[url]http://hq.sinajs.cn/list=sz002004[/url](没办法对华邦制药有点感觉- -!)
先是编码问题 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 :D
最后找到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 : "");
}
看来以后还得多看看源码啊 完全搞懂这些框架 :idea:
第一次发帖 呵呵 不知道效果啥样