Ajax获取带有无用参数的请求 [英] Ajax get request with useless parameter

查看:240
本文介绍了Ajax获取带有无用参数的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试执行下一个:

$.ajax({
type: 'GET',
url: 'http://127.0.0.1:6789/dir', 
data: "",   
success: function(data) { /*do something*/ },
dataType: 'html'
});

但是,当它执行时,我的服务器会收到类似以下的内容:

But when it executes, my server receives something like below:

http://127.0.0.1:6789/dir?_32567871112

我不想传递任何参数.我怎么了

I don't want to pass any parameters. What do I wrong?

推荐答案

简而言之,在$.ajax调用选项中将cache设置为true.

In short, set cache to true in your $.ajax call's options.

jQuery将其添加到缓存中.

jQuery adds that for cache breaking.

jQuery中有一个选项可以将其关闭:(来自 http://api.jquery. com/jQuery.ajax/)

There is an option in jQuery to turn that off: (from http://api.jquery.com/jQuery.ajax/)

cache

默认值:truefalse用于数据类型'script'和'jsonp'

Default: true, false for dataType 'script' and 'jsonp'

如果设置为false,它将强制请求的页面不被缓存 浏览器.将缓存设置为false还会附加一个查询字符串参数, 网址的网址为"_ = [TIMESTAMP]".

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.

cache设置为true的示例:

$.ajax({
  type: 'GET',
  cache: true,
  url: 'http://127.0.0.1:6789/dir',
  data: "",
  success: function (data) { /*do something*/
  },
  dataType: 'html'
});

这篇关于Ajax获取带有无用参数的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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