Advertisement
SUNSPINX

Untitled

Aug 22nd, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2.             $(function() {
  3.                 var ajaxURL = "";
  4.                 var gameId = "";
  5.                 var cycle = "";
  6.                 var slots = "";
  7.  
  8.                 $('#product').change(function(){
  9.                     gameId = $(this).val();
  10.                     ajaxURL = 'user/<?=$_SESSION['lang']?>/ajax/order/game/' + gameId;
  11.                     updateProductInfo();
  12.                 });
  13.  
  14.                 // Aktualizace cyklu
  15.                 $('#cycle').change(function() {
  16.                     cycle = $(this).val();
  17.                     updateProductInfo();
  18.                 });
  19.  
  20.                 // Aktualizace počtu slotů
  21.                 $('#slot').change(function() {
  22.                     slots = $(this).val();
  23.                     updateProductInfo();
  24.                 });
  25.  
  26.                 function updateProductInfo() {
  27.                     $.ajax({
  28.                         // Dobrovolné, defaultně je to GET,
  29.                         // podle toho na serveru $_POST[], $_GET[]
  30.                         // (do GET nedávat hesla a citlivé údaje!)
  31.                         method : 'POST',
  32.                         // URL adresa pro AJAX kontroler s příslušnými dodatečnými parametry
  33.                         // Pokud nepůjde relativní, zkusit absolutní
  34.                         url : ajaxURL,
  35.                         // Data pre PHP
  36.                         data: {cycle: cycle, slots: slots}
  37.                         // Návratový typ HTML
  38.                         // Další přijatelné a často používané:
  39.                         // json (když potřebuješ vrátit pole - musí být v JS formátu!!), text, xml
  40.                         dataType : 'html',
  41.                         // Povolit cachování
  42.                         cache: true,
  43.                         // Funkce volaná při úspěchu
  44.                         success : function(gameInfo) {
  45.                             $("#product-info").html(gameInfo);
  46.                             console.log(gameInfo);
  47.                         },
  48.                         // Pokud požadavek selže
  49.                         error : function(error) {
  50.                             console.log(error);
  51.                         }
  52.                     });
  53.                 }
  54.             });
  55.         </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement