Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript][AJAX]Kod nie wykonuje sie za kazdym razem, Dlaczego tak sie dzieje?
Twist
post
Post #1





Grupa: Zarejestrowani
Postów: 174
Pomógł: 11
Dołączył: 12.10.2008
Skąd: Dublin

Ostrzeżenie: (0%)
-----


Mamy nastepujacy kod:
Najpierw wywouluej funkcje, ktora laduej reszte

  1. $("a#showA").click(function () {
  2. getHotelInfo(apiKey);
  3. });


I po kolei:

  1. function getHotelInfo(yourAPIKey) {
  2. var enquiry = "XXX; //tutaj url do wykonania
  3. //alert(enquiry);
  4. $.ajax({
  5. url: enquiry,
  6. type: 'GET',
  7. dataType: "jsonp",
  8. jsonp: "callback",
  9. jsonpCallback: "jsonpCallback2",
  10. complete: function (response, responseCode) {
  11. },
  12. success: function (json) {
  13. $.each(json.Contracts, function (index, contract) {
  14. getAvailability(yourAPIKey, contract.ContractCode, startDate, endDate);
  15. getRates(yourAPIKey, contract.ContractCode, startDate, endDate);
  16. alert(contract.ContractCode + " - done "); // <---- O TYM MOWIE
  17. });
  18. }
  19. });
  20. }


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:

  1. function populateValues(Type, Contractname, RoomType, Date, val) {
  2. $("input#" + Type + "_IE-ORK-IN-32966275_" + Contractname + "_" + RoomType + "_" + Date).val(val);
  3. // alert("input#" + Type + "_" + Contractname + "_" + RoomType + "_" + Date + " -> " + val);
  4. }
  5.  
  6. function getRates(yourAPIKey, contractCode, startDate, endDate) {
  7. var ratesEnquiry = "URL + yourAPIKey + "&contractCode=" + contractCode + "&startDate=" + startDate + "&endDate=" + endDate;
  8.  
  9. $.ajax({
  10. url: ratesEnquiry,
  11. type: 'GET',
  12. dataType: "jsonp",
  13. jsonp: "callback",
  14. jsonpCallback: "jsonpCallback3",
  15. complete: function (response, responseCode) {
  16. //console.log(response); console.log(responseCode);
  17. //alert("complete");
  18. },
  19. success: function (json) {
  20. $.each(json, function (index, value) {
  21. // populateValues("rate", this.ContractCode, this.RoomTypeCode, this.Date.substr(0, 10), this.RoomPrice);
  22. // populateValues("hrate", this.ContractCode, this.RoomTypeCode, this.Date.substr(0, 10), this.RoomPrice);
  23. });
  24. }
  25. });
  26. }
  27.  
  28. function getAvailability(yourAPIKey, contractCode, startDate, endDate) {
  29. var availabilityEnquiry = "[i]URL[/i]" + yourAPIKey + "&contractCode=" + contractCode + "&startDate=" + startDate + "&endDate=" + endDate;
  30. $.ajax({
  31. url: availabilityEnquiry,
  32. type: 'GET',
  33. dataType: "jsonp",
  34. jsonp: "callback",
  35. jsonpCallback: "jsonpCallback",
  36. complete: function (response, responseCode) {
  37. //console.log(response); console.log(responseCode);
  38. //alert("complete");
  39. },
  40. success: function (json) {
  41. $.each(json, function (index, value) {
  42. //populateAvailability(this.Date.substr(0, 10), this.RoomTypeCode, this.ContractCode, this.Quantity);
  43. populateValues("avail", this.ContractCode, this.RoomTypeCode, this.Date.substr(0, 10), this.Quantity);
  44. populateValues("havail", this.ContractCode, this.RoomTypeCode, this.Date.substr(0, 10), this.Quantity);
  45. });
  46. }
  47. });
  48. }



Powiedzialby, że to dziwne. Ale nauczylem sie, ze jak coś jest dziwne, to znaczy, ze tego nie rozumiem. Moze mi ktos wytlumaczy?
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 24.08.2025 - 09:42