setOnClickAsync( // Task that runs in background thread onClickAsync: function() { // Simulate web request (or use real HTTP client) sleep(2); // Simulates network delay // In production, you would use something like: // $response = file_get_contents('https://api.example.com/data'); // return json_decode($response, true); return [ 'status' => 'success', 'data' => 'Daten erfolgreich geladen!', 'timestamp' => date('H:i:s') ]; }, // Callback when task completes successfully onComplete: function($result) use ($statusLabel, $resultLabel) { $statusLabel->setText('✓ Laden abgeschlossen!'); $resultLabel->setText( 'Status: ' . $result['status'] . "\n" . 'Daten: ' . $result['data'] . "\n" . 'Zeit: ' . $result['timestamp'] ); }, // Callback when task fails onError: function($error) use ($statusLabel, $resultLabel) { $statusLabel->setText('✗ Fehler beim Laden!'); $resultLabel->setText('Error: ' . $error->getMessage()); } ); // Add components to container $container->addComponent($statusLabel); $container->addComponent($button); $container->addComponent($resultLabel); // Set root component and run $app->setRoot($container)->run();