Najpierw wywouluej funkcje, ktora laduej reszte
$("a#showA").click(function () { getHotelInfo(apiKey); });
I po kolei:
function getHotelInfo(yourAPIKey) { var enquiry = "XXX; //tutaj url do wykonania //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) { getAvailability(yourAPIKey, contract.ContractCode, startDate, endDate); getRates(yourAPIKey, contract.ContractCode, startDate, endDate); alert(contract.ContractCode + " - done "); // <---- O TYM MOWIE }); } }); }
Funkcje getAvailability i getRates - powinny sie wekonac dwukrotnie. I tak jest - wszystko super. Problem polega na tym, że gdy usune alert to te funkcje wykonuje sie tyko raz.
oto te 2 funkcje oraz tzrecia, ktorej obie uzywaja:
// alert("input#" + Type + "_" + Contractname + "_" + RoomType + "_" + Date + " -> " + val); } function getRates(yourAPIKey, contractCode, startDate, endDate) { var ratesEnquiry = "URL + yourAPIKey + "&contractCode=" + contractCode + "&startDate=" + startDate + "&endDate=" + endDate; $.ajax({ url: ratesEnquiry, type: 'GET', dataType: "jsonp", jsonp: "callback", jsonpCallback: "jsonpCallback3", complete: function (response, responseCode) { //console.log(response); console.log(responseCode); //alert("complete"); }, success: function (json) { $.each(json, function (index, value) { // populateValues("rate", this.ContractCode, this.RoomTypeCode, this.Date.substr(0, 10), this.RoomPrice); // populateValues("hrate", this.ContractCode, this.RoomTypeCode, this.Date.substr(0, 10), this.RoomPrice); }); } }); } function getAvailability(yourAPIKey, contractCode, startDate, endDate) { var availabilityEnquiry = "[i]URL[/i]" + yourAPIKey + "&contractCode=" + contractCode + "&startDate=" + startDate + "&endDate=" + endDate; $.ajax({ url: availabilityEnquiry, type: 'GET', dataType: "jsonp", jsonp: "callback", jsonpCallback: "jsonpCallback", complete: function (response, responseCode) { //console.log(response); console.log(responseCode); //alert("complete"); }, success: function (json) { $.each(json, function (index, value) { //populateAvailability(this.Date.substr(0, 10), this.RoomTypeCode, this.ContractCode, this.Quantity); populateValues("avail", this.ContractCode, this.RoomTypeCode, this.Date.substr(0, 10), this.Quantity); populateValues("havail", this.ContractCode, this.RoomTypeCode, this.Date.substr(0, 10), this.Quantity); }); } }); }
Powiedzialby, że to dziwne. Ale nauczylem sie, ze jak coś jest dziwne, to znaczy, ze tego nie rozumiem. Moze mi ktos wytlumaczy?