2016-05-10 101 views
0

Im試圖解析一個使用XmlRequest的鏈接,但我得到404錯誤,沒有什麼是錯的,它的工作正常的鏈接, 谷歌搜索後,我認爲這個問題可能與我的配置我不知道如何啓用CORS並將其添加到我的applicationhost.config 任何幫助都會被解決。 這裏是我的代碼:在Visual Studio 2015中啓用CORE

的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(); 

enter image description here

enter image description here

enter image description here

enter image description here

回答

0

剛剛重新啓動計算機,也將努力:d

+0

並不是每一個問題得到重啓計算機解決了:( – agustin