0
Im XmlRequestを使用してリンクを解析しようとしていますが、404エラーが表示されても、リンクに問題はありません。 CORSを有効にして、それを私のapplicationhost.configに追加してください。 何か助けが必要です。Visual StudioでCORSを有効にする2015
のindex.html: はここに私のコードです
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<title>Ticket</title>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
<meta http-equiv="refresh" content="5">
</head>
<body>
<button onclick="Next();">Next</button>
<footer id="currentTicket">loading...</footer>
</body>
Script.JS
var currentTicketId = 0;
var lastTicket;
function GetCurrentTicketId() {
var request = HttpRequest("http://localhost:6164/api/tickets?IsDone=false",
"GET", "");
request.onreadystatechange = function() {
if (request.readyState == 4) {
if (request.status == 200) {
var Ticket = JSON.parse(request.responseText);
lastTicket = Ticket;
currentTicketId = Ticket.id;
document.getElementById("currentTicket").innerHTML = "current
ticket is " + Ticket.ticketNumber;
}
else {
document.getElementById("currentTicket").innerHTML = "Error";
}
}
}
}
function HttpRequest(Url, Method, Parameter) {
var httpClient = new XMLHttpRequest();
httpClient.open(Method, Url, true);
httpClient.setRequestHeader("Content-type", "application/x-www-form-
urlencoded");
httpClient.send(Parameter);
return httpClient;
}
function Next() {
var request = HttpRequest("http://localhost:6164/api/tickets" +
currentTicketId, "PUT", lastTicket);
request.onreadystatechange = function() {
if (request.readyState == 4) {
if (request.status == 200) {
var Ticket = JSON.parse(request.responseText);
lastTicket = Ticket;
currentTicketId++;
document.getElementById("currentTicket").innerHTML = "current
ticket is " + Ticket.ticketNumber;
} else {
document.getElementById("currentTicket").innerHTML = "no more
taken tickets";
}
}
}
}
GetCurrentTicketId();
は、すべての問題は、コンピュータを再起動することで解決されませ:( – agustin