-1
我有兩個AJAX請求,兩個正在檢查是否沒有獲獎點的新評級可用。ajax請求與url作爲變量不能正常工作
,如果我通過本地主機訪問我的應用程序沒關係:8080或IP地址:8080,與映射兩個web服務「/ nextRating」正在提供一個評價,如果有的話。
我創建了兩個全局變量,URL1和URL2,一個用於Web服務和一個用於網站,應加載,如果請求中的成功。
函數中的第二個請求正常工作。
第一個不,我只是不明白爲什麼。
function checkForNewRating()
{
//Extracts the Ip from the url, if accessed via IP:8080/...
getIp();
if (ip != null) {
url1 = ip.toString() + ":8080/feedback/nextRating";
url2 = ip.toString() + ":8080/feedback/app";
$.ajax({
type: "GET",
url: url1,
dataType: "json",
success: function (data) {
console.log(data);
window.location.assign(url2);
},
error: function()
{
console.log(window.location.href);
}
})
}
else {
$.ajax({
type: "GET",
url: "http://localhost:8080/feedback/nextRating",
dataType: "json",
success: function (data) {
console.log(data);
window.location.assign("http://localhost:8080/feedback/app");
},
error: function() {
console.log(window.location.href);
}
})
}
}
請求的代碼
function getIp() {
if (href.includes("192.168.")) {
var startIndex = href.indexOf("1");
var endIndex = href.indexOf(":8")
ip = href.substring(startIndex, endIndex);
}
}
此功能工作正常,URL的變量越來越設置正確
什麼是'ip'變量的值?你在哪裏分配它? – karthick
在getIp()開頭 – crunpy
你可以發佈'getIp'代碼嗎? – Hackerman