jquery - $.ajax 调用附加某种额外的查询参数

标签 jquery asp.net-mvc-4

我正在通过 IIS Express 运行 ASP.NET MVC 站点。

例如,我设置了这个测试页面:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" language="javascript" type="text/javascript"></script>

<script language="javascript" type="text/javascript">

    var carServiceUrl = "http://localhost:43889/cars";

    $(document).ready(function ()
    {
        $.ajaxSetup(
        {
            cache: false,
            dataType: "json"
            contentType: "application/json"
        });

    });

    get();

    function get()
    {
        var url = carServiceUrl;

        $.ajax({
            cache: false,
            type: "GET",
            async: true,
            url: carServiceUrl,
            dataType: "json",

            success: onGetCarsSuccess
        });
    }

 </script>

</body>
</html>

问题是当我启动 FireBug 并加载此页面时, get() 被触发,但请求在查询字符串中具有某种附加值(例如 http://localhost:43889/cars?_=1381820301163),我不知道它是如何到达那里的。我不知道这是因为我在 MVC 项目中运行它还是因为我通过 IIS Express 运行所有这些。我通常直接使用 IIS,所以不确定。

我不确定为什么它会将 ?_=1381820301163 附加到请求中。我从未在 jQuery 调用中指定这一点。

最佳答案

来自 jQuery ajax 文档:

http://api.jquery.com/jQuery.ajax/

cache (default: true, false for dataType 'script' and 'jsonp')

Type: Boolean

If set to false, it will force requested pages not to be cached by the browser. Note: Setting cache to false will only work correctly with HEAD and GET requests. It works by appending "_={timestamp}" to the GET parameters. The parameter is not needed for other types of requests, except in IE8 when a POST is made to a URL that has already been requested by a GET.

关于jquery - $.ajax 调用附加某种额外的查询参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19375131/

相关文章:

javascript - 哈希作为选中复选框的值,如果取消选中复选框则删除

javascript - 有没有办法等待 AJAX 响应并停止执行?

asp.net-mvc-4 - 找出十六进制颜色是深还是浅

c# - Telerik 报告参数日期时间不起作用

c# - MVC HttpPostedFileBase 始终为空

jquery - 使用工具提示显示表的行详细信息 (jQuery)

php - jQuery ajax 输出作为函数的返回

javascript - 当我点击它时如何突出显示html页面中的按钮?

c# - 模板 C#/MVC 4/Razor

c# - 尝试通过安全透明方法访问安全关键类型失败