我在Android手機(運行在ANdroid 2.2上的Samsung Galaxy mini)中運行此應用程序。我爲我的數據庫使用了couchdb,並將它託管在cloudant上。GET HTTPs請求在電話中無法正常工作
在設備準備就緒後,應用程序將向https數據庫服務器發出獲取請求,其中包含需要在我的應用中顯示的數據提要。起初,它工作正常,但當我嘗試發佈並向https數據庫服務器添加新數據時,然後觸發get請求方法,從服務器返回的響應仍然與以前相同(新發布的數據未包括在內即使我檢查了我的數據庫服務器,看到它確實保存了)。然後我嘗試關閉並重新打開應用程序,然後再創建一個get http請求的新實例,但仍然是,響應仍然與第一個相同,並且不包含添加到數據庫的新數據服務器。然後,我嘗試重新安裝我的應用程序,然後再次運行應用程序,奇怪的是,來自get請求的響應現在包含新數據..我不知道這是怎麼發生的,而且我對REST並不是很有經驗API和JavaScript,所以我可能會做一些明顯錯誤的事情。下面是我的獲取請求代碼片段:
var getFeedsClient;
document.addEventListener(「deviceready」,onDeviceReady,false);
function onDeviceReady() {
if (window.XMLHttpRequest) {
getFeedsClient=new XMLHttpRequest();
}
else {
getFeedsClient=new ActiveXObject("Microsoft.XMLHTTP");
}
try{
getFeedsRequest();
} catch(e)
{
alert("Error on device ready: "+e);
}
}//on Device Ready
function getFeedsRequest() {
getFeedsClient.onreadystatechange = getFeedsFunction;
getFeedsClient.open("GET","https://<username>.cloudant.com/te/_design/requestfeed/_view/all",true);
getFeedsClient.send();
}
function getFeedsFunction() {
alert(" readystate: "+getFeedsClient.readyState+", status: "+getFeedsClient.status);
if(getFeedsClient.readyState == 4 && getFeedsClient.status == 200) {
var data = JSON.parse(getFeedsClient.responseText);
console.log("RESPONSE FROM COUCHDB "+getFeedsClient.responseText);
console.log("JSON data "+data);
//at first the total rows is 2 but when a new data was added, the total rows should be three, but that was not the case
alert("rows: "+data.total_rows);
}
}