去http://starodaj.eu/apitest/index2.html查看我的代码
单击“显示可用性”。它应该填充输入。我有一个问题(可能是异步的),所以我无法通过单击填充所有内容。当我多次单击“ShowAvailability”时 - 一切正常。我该如何解决?
function callAPI(yourAPIKey){
var enquiry = "http://api.roomex.com/api/hotel?apiKey=" + yourAPIKey;
//alert(enquiry);
$.ajax({
url: enquiry,
type: 'GET',
dataType: "jsonp",
jsonp: "callback",
jsonpCallback: "jsonpCallback2",
complete: function (response, responseCode) {
},
success: function (json) {
$.each(json.Contracts, function (index, contract) {
// alert("Count before increament : " + Count);
// alert(contract.ContractCode);
ContractsArray[Count] = contract.ContractCode;
// alert("Count after increament : " + Count);
// alert("ContractsArray[Count]: " + ContractsArray[Count]);
Count++;
});
for(var i = 0; i < Count; i++){
//alert("ContractsArray[" + i + "]: " + ContractsArray[i]);
getAvailability(yourAPIKey, ContractsArray[i], startDate, endDate);
getRates(yourAPIKey, ContractsArray[i], startDate, endDate);
//alert("Finish of ContractsArray[" + i + "]: " + ContractsArray[i]);
}
}
});
}