Advertisement
lord_shadow

Untitled

Aug 6th, 2023 (edited)
1,279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $w.onReady(function () {
  2.   $w("#button1").onClick(sendPromoteRequest);
  3.   $w('#button2').hide();
  4.   $w('#button3').hide();
  5.   $w("#successMessage").hide();
  6. });
  7.  
  8. const url = 'myurl:3001';
  9. const key = 'myapikey';
  10.  
  11. function sendPromoteRequest() {
  12.   const playerId = $w("#input1").value;
  13.  
  14.   const requestOptions = {
  15.     method: 'POST',
  16.     Authorization: key,
  17.     headers: {
  18.       'Content-Type': 'application/json',
  19.       'Authorization': key,
  20.     },
  21.     body: JSON.stringify({
  22.       id: playerId,
  23.     })
  24.   };
  25.  
  26.   fetch(`${url}/promote`, requestOptions)
  27.     .then(response => response.json())
  28.     .then(data => {
  29.       console.log("API request successful!");
  30.       console.log("Response:", data);
  31.       $w("#successMessage").text = `Successfully promoted robloxId: ${playerId}`;
  32.       $w("#successMessage").show();
  33.  
  34.       setTimeout(() => {
  35.         $w("#successMessage").hide();
  36.         $w("#button2").label = "Confirm";
  37.         cancelRequest();
  38.       }, 2000);
  39.     })
  40.     .catch(error => {
  41.       console.error("Failed to make API request:", error);
  42.       setTimeout(() => {
  43.         $w("#button2").label = "Confirm";
  44.         cancelRequest();
  45.       }, 2000);
  46.     });
  47. }
  48.  
  49. function cancelRequest() {
  50.   $w("#button2").hide();
  51.   $w("#button3").hide();
  52.   $w("#button1").show();
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement