AJAX GET请求不发送任何内容

问题描述 投票:-1回答:1

我目前正在尝试在AJAX中测试自定义标头,但是当我用下面的html函数打开JS文件时,没有请求。 Edge在大约30秒之后才说Response got loaded from cache。有人知道为什么会这样吗?

<html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
        <script>
            function load() {
                //$.ajaxSetup({headers: { "CustomHeader": "myValue" }});
                alert("loaded");
            }

            function request() {
                var settings = {
                    "crossDomain": true,
                    "url": "http://localhost:11280/AmbrosiaREST.svc/TestCookie",
                    "method": "GET",
                    "headers": {
                        "Content-Type": "application/json",
                        "SessionID": "IDNOSET",
                        "UserID": "2",
                        "Cache-Control": "no-cache"
                    },
                    "processData": true
                }

                $.ajax(settings).done(function (response) {
                    alert(response);
                }).fail((response) => {
                    console.log(response);
                }).always(() => {
                    console.log("sth");
                })
            }
        </script>
    </head>
    <body onload="load()">
        <button type="button" onclick="request()">Send smth</button>
    </body>
</html>
javascript jquery html ajax
1个回答
0
投票

根据HTTP版本(1.0,1.1等)和浏览器,这应该适用于某些较旧的版本,如IE6。

function request() {
  var settings = {
    "crossDomain": true,
    "url": "http://localhost:11280/AmbrosiaREST.svc/TestCookie",
    "method": "GET",
    "headers": {
      "Content-Type": "application/json",
      "SessionID": "IDNOSET",
      "UserID": "2",
      "Cache-Control": "no-cache, no-store, must-revalidate",
      "Pragma": "no-cache",
      "Expires": 0
    },
    "processData": true
  }

  $.ajax(settings).done(function(response) {
    alert(response);
  }).fail((response) => {
  console.log("fail");
    console.log(response);
  }).always(() => {
    console.log("sth");
  })
}
request()
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
© www.soinside.com 2019 - 2024. All rights reserved.