我目前正在尝试在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>
答案 0 :(得分: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()
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
&#13;