六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 67|回复: 0

jquery的script类型ajax请求

[复制链接]

升级  62%

7

主题

7

主题

7

主题

童生

Rank: 1

积分
31
 楼主| 发表于 2013-1-29 11:38:46 | 显示全部楼层 |阅读模式
最近做个小东西用到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 therevar ret = s.url.replace(rts, "$1_=" + ts);// if nothing was replaced, add timestamp to the ends.url = ret + ((ret === s.url) ? (rquery.test(s.url) ? "&" : "?") + "_=" + ts : "");}
看来以后还得多看看源码啊 完全搞懂这些框架
第一次发帖 呵呵 不知道效果啥样
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表