为什么加了一些数字给url Ajax对象以及如何删除? [英] Why some numbers are added to url of ajax object and how to remove them?

查看:185
本文介绍了为什么加了一些数字给url Ajax对象以及如何删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想下载文件的进一步使用,这是我找到的最好的方式,但是当我看到由 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({高速缓存:真})。
 

jQuery的阿贾克斯文档

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 to false, it will force requested pages not to be cached by the browser. Setting cache to false also appends a query string parameter, "_=[TIMESTAMP]", to the URL.

$.ajaxSetup({'cache':true});

Jquery Ajax Docs

这篇关于为什么加了一些数字给url Ajax对象以及如何删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆