Kan dit eenvoudiger?

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Louis Deconinck

Louis Deconinck

28/09/2021 15:00:44
Quote Anchor link
Ik heb drie knoppen op mijn website, deze doen telkens min of meer hetzelfde met iets andere info. Ik denk dat eenvoudiger zou moeten kunnen, maar weet niet excact hoe. Enige hulp?

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<button id="send_1">Buy 1 day</button>
<button id="send_30">Buy 30 days</button>
<button id="send_100000">Buy Lifetime</button>

 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"
      integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ=="
      crossorigin="anonymous" referrerpolicy="no-referrer"></script>
      
      <script>
$("#send_1").click(function () {
  console.log("click");
  hive_keychain.requestCustomJson(
    null, 'sm_token_transfer', 'active', '{"to":"eclipsi","qty":95,"token":"DEC","type":"withdraw","app":"splinterviewer"}', '1 day',
    function (response) {
        console.log(response);
        console.log(response.data.username);
        console.log(response.result.id);

        $.post("purchase.php", { name : response.data.username, days : 1 });
    }
  );
});
  
   $("#send_30").click(function () {
  console.log("click");
  hive_keychain.requestCustomJson(
    null, 'sm_token_transfer', 'active', '{"to":"eclipsi","qty":1195,"token":"DEC","type":"withdraw","app":"splinterviewer"}', '30 days.',
    function (response) {
        console.log(response);
        console.log(response.data.username);
        console.log(response.result.id);

        $.post("purchase.php", { name : response.data.username, days : 30 });
    }
  );
});

   $("#send_100000").click(function () {
  console.log("click");
  hive_keychain.requestCustomJson(
    null, 'sm_token_transfer', 'active', '{"to":"eclipsi","qty":26995,"token":"DEC","type":"withdraw","app":"splinterviewer"}', 'Lifetime',
    function (response) {
        console.log(response);
        console.log(response.data.username);
        console.log(response.result.id);

        $.post("purchase.php", { name : response.data.username, days : 100000 });
    }
  );
});
</script>
    </body>
</html>
 
PHP hulp

PHP hulp

09/12/2021 05:31:01
 
- Ariën -
Beheerder

- Ariën -

28/09/2021 15:04:22
Quote Anchor link
Gebruik functies.
 
Adoptive Solution

Adoptive Solution

28/09/2021 19:20:59
Quote Anchor link
Met wat zoeken en puzzelen :

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<button id="send_1" onclick="clickbtn( this.id )">Buy 1 day</button>
<button id="send_30" onclick="clickbtn( this.id )">Buy 30 days</button>
<button id="send_100000" onclick="clickbtn( this.id )">Buy Lifetime</button>

<p id="result"></p>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>

<script>

var obj = {
    'send_1': {
        'qty': 95,
        'days': '1 day'
        },
    'send_30': {
        'qty': 1195,
        'days': '30 days'
        },
    'send_100000': {
        'qty': 26995,
        'days': 'Lifetime'
        }
    };

function clickbtn( id ) {
    document.getElementById('result').innerHTML = 'Aantal = ' + obj[id]['qty'] + '<br />' + 'Dagen = ' + obj[id]['days'];
    // verder verwerken
}

</script>


Bron van inspiratie :
https://stackoverflow.com/questions/4329092/multi-dimensional-associative-arrays-in-javascript
Gewijzigd op 28/09/2021 19:23:22 door Adoptive Solution
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.