Page 1 of 1

Hello, I would like to show de data from the api once it is log in, at the moment the log in is correct but the dat is n

Posted: Fri May 20, 2022 11:47 am
by answerhappygod
Hello, I would like to show de data from the api once it is log
in, at the moment the log in is correct but the dat is not showed
on the app, this is what I have:
HTML:
<title>****</title>
</head>
<body>
<h1>***</h1>
<!-- Identify the salesperson by
their OUCU and password, and the client by a valid client id
(entry methods to capture required
data)--->
<label
for="oucu">OUCU:</label>
<input type="text" id="oucu" name="oucu"
required>
<p>
<label
for="password">Password:</label>
<input type="password" id="password"
name="password" required>
<p>
<label for="client_id">Your
ID:</label>
<input type="number" id="client_id"
name="client_id" required>
<minlength="8" maxlength="8"
size="10">
<p>
<!--- button to log in and update map
-->
<button type="button"
onclick="controller.beginorder()">Login</button>
<p>
<div id= "app"></div>
JSON:
// Request an show the information for the given
OUCU
function request(oucu, password, client_id) {
// Creating form data and append values
passed as parameters
var formData = new FormData();
formData.append("oucu", oucu);
//formData.append("type", "1");
formData.append("password",
password);
formData.append("client_id",
client_id);
//"http://137.108.92.9/openstack/api/clien ... &password=*******"

var url = BASE_URL + "clients/" +
client_id + "?OUCU=" + oucu + "&password=" + password;
// Create an XMLHttpRequest object
var xhr = new XMLHttpRequest();
// Define a Callback Function, alert
to the user with a message
xhr.onload = function () {
var obj =
JSON.parse(xhr.responseText);
console.log("request:
received obj", obj);
if (obj.status ==
"success") {

alert("Client " + oucu + " has made a successful Login");
} else if (obj.message)
{

alert(obj.message);
} else {

alert(obj.status + " " + obj.data[1].reason);
}
}
// Send a Request
xhr.open("GET", url, true);
xhr.send(formData);
console.log("request: sending get to " +
url);
}
// Controller function for user to request to show client
information.
this.beginorder = function () {
var oucu =
getInputValue("oucu", "*******");
var password =
getInputValue("password", "*****");
var client_id =
getInputValue("client_id", "1");
// Call the model using
values from the view
request(oucu, password,
client_id);
};
API INFO:
{
"status" : "success",
"data" :
[
{
"id":"1",
"name":"Widgets Galore",
"address":"555 Silbury Blvd, Milton Keynes MK9 3HL",
"phone":"0123 456 789",
"email":[email protected]
}
]
}
Thank you!