From ede9ecc7b6792f6f473416c5dbf91ba7adb2a1e2 Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Fri, 27 Sep 2024 09:49:50 +0300 Subject: [PATCH] Adds initial ajax call to agents api --- app/templates/agent-list.php | 5 ++++- app/templates/page-header.php | 3 +++ public_html/static/agents.js | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 public_html/static/agents.js diff --git a/app/templates/agent-list.php b/app/templates/agent-list.php index fe763b8..74197cc 100644 --- a/app/templates/agent-list.php +++ b/app/templates/agent-list.php @@ -6,7 +6,10 @@

agent id: type , url - + +

+

Result:

+
click a button to fetch data from the agent.
diff --git a/app/templates/page-header.php b/app/templates/page-header.php index 6a7cab8..028210a 100644 --- a/app/templates/page-header.php +++ b/app/templates/page-header.php @@ -23,6 +23,9 @@ } })(); + + + Jilo Web diff --git a/public_html/static/agents.js b/public_html/static/agents.js new file mode 100644 index 0000000..c8a57f8 --- /dev/null +++ b/public_html/static/agents.js @@ -0,0 +1,20 @@ +function fetchData(force = false) { + // Show loading text + document.getElementById("result").innerHTML = "Loading..."; + + // Create an AJAX request + var xhr = new XMLHttpRequest(); + xhr.open("POST", "index.php?page=agents", true); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + + xhr.onreadystatechange = function() { + if (xhr.readyState === 4 && xhr.status === 200) { + // Parse and display the result + let result = JSON.parse(xhr.responseText); + document.getElementById("result").innerHTML = JSON.stringify(result, null, 2); + } + }; + + // Send the AJAX request, with force flag + xhr.send("action=fetch&force=" + (force ? 'true' : 'false')); +}