为什么加了一些数字给url Ajax对象以及如何删除? [英] Why some numbers are added to url of ajax object and how to remove them?
问题描述
我想下载文件的进一步使用,这是我找到的最好的方式,但是当我看到由 beforeSend
事件创建日志,URL已通过查询字符串被修改,如:
http://blabla.com/test.swf?_=1346484617818
数字是随机的了。
我不知道为什么会这样!!!!
VAR URL ='http://blabla.com/test.swf';
$(文件)。就绪(函数(){
$ .ajaxSetup({
beforeSend:函数(){
执行console.log(this.url);}
});
$阿贾克斯({
网址:网址,
数据类型:剧本,
});
});
只需使用缓存:真。 jQuery将时间戳自动添加到URL为你的末尾,确保Ajax请求不会被缓存。
从jQuery的文档
默认:真,假的dataType的脚本和JSONP
如果设置为假
,这将迫使请求的页面不被浏览器缓存。 设置缓存为假
还追加查询字符串参数,_ = [TIMESTAMP]
,到URL。
$ ajaxSetup({高速缓存:真})。
I Wanna download file for further use, this is the best way I've found, but when I see the Log that is created by beforeSend
Event, the URL has been modified by a queryString like:
http://blabla.com/test.swf?_=1346484617818
Numbers are random too.
I wonder why this happens !!!!
var url = 'http://blabla.com/test.swf';
$(document).ready(function () {
$.ajaxSetup({
'beforeSend':function () {
console.log(this.url);}
});
$.ajax({
url:url,
dataType:"script",
});
});
Just use cache : true. jQuery will automatically add a timestamp to the end of the URL for you, making sure that ajax requests are never cached.
from jquery docs
Default: true, false for dataType 'script' and 'jsonp'
If set tofalse
, it will force requested pages not to be cached by the browser. Setting cache tofalse
also appends a query string parameter, "_=[TIMESTAMP]
", to the URL.
$.ajaxSetup({'cache':true});
这篇关于为什么加了一些数字给url Ajax对象以及如何删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!