In this challenge, you'll create a simple USSD (Unstructured Supplementary Service Data) application interface using HTML, CSS, JavaScript, and AJAX to interact with a PHP server endpoint. USSD applications are used in mobile networks for services like balance checks, mobile banking, and more. This task will help you understand how USSD interactions can be simulated in a web environment and dynamically handled through server-side logic. Using AJAX, you will create a sample USSD app that communicates with a PHP server to simulate a simple banking menu system, allowing real-time data exchange and interaction based on user inputs.
The USSD app will simulate the following menu structure:
1. Check Balance 2. Transfer Money 3. Buy Airtime 4. Exit
Each menu option will lead to further actions or submenus. For simplicity, we will only implement the first two options with basic interactions using AJAX to communicate with the PHP server.
<?php
header('Content-Type: application/json');
$input = isset($_POST['input']) ? $_POST['input'] : '';
$currentMenu = isset($_POST['currentMenu']) ? $_POST['currentMenu'] : 'main';
$response = array('output' => '', 'currentMenu' => 'main');
if ($currentMenu === 'main') {
switch ($input) {
case '1':
$response['output'] = '<p>Your balance is KES 1,000/=</p><p>0. Main Menu</p>';
break;
case '2':
$response['output'] = '<p>Enter amount to transfer:</p>';
$response['currentMenu'] = 'transfer';
break;
case '3':
$response['output'] = '<p>Enter amount to buy airtime:</p>';
$response['currentMenu'] = 'airtime';
break;
case '4':
$response['output'] = '<p>Thank you for using Bora Wallet. Goodbye!</p>';
$response['currentMenu'] = 'exit';
break;
default:
$response['output'] = '<p>Invalid option. Try again.</p><p>1. Check Balance</p><p>2. Transfer Money</p><p>3. Buy Airtime</p><p>4. Exit</p>';
}
} elseif ($currentMenu === 'transfer') {
$response['output'] = '<p>Transfer amount KES
' . htmlspecialchars($input) . '/= </p><p>0. Main Menu</p><p>4. Exit</p>';
} elseif ($currentMenu === 'airtime') {
$response['output'] = '<p>Buy airtime of amount KES
' . htmlspecialchars($input) . '/= </p><p>0. Main Menu</p><p>4. Exit</p>';
}
echo json_encode($response);
This is an example of what the app should display. Feel free to get creative with it.
Create a zip of your attempt including snapshots of your menus then forward it to:
or Email: playground@ilebora.com
Feel free to interact with me for support:
HAPPY CODING!!!