Source Code : call_Service_test.html
<script type="text/javascript">
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Όνομα Ζώο Φυτό - Το παιχνίδι </title>
<script src="tests_pretty.js"></script>
</head>
<body>
Example :
<mark>Services Word Games</mark>
<br/>
<br/>
<br/>
<script>
displayInfo(" api : " + URL, null, 'url');
const data = {
"configuration": ['GRStemmer', "", ""],
'word': ' Απόδειξη ',
'words': ['Κώστας', "Καγκουρό", "Κυκλάμινο"],
};
fetch(URL, {
method: "POST",
body: JSON.stringify(data),
headers: {
"Content-type": "application/json;
charset=UTF-8"
}
}).then(response => response.json())
.then(dataRet => {
displayInfo(" Service Call ", data, 'retCall');
// const returnJSON = JSON.parse(dataRet);
// displayInfo(sPlugin + " Returns Json ", returnJSON, 'retInfo');
displayInfo(" Response ", response, 'retCaall');
// document.write("Status " + JSON.stringify(resp.status, null) + "<br/>");
// document.write("Return " + JSON.stringify(resp.statusText, null));
})
.catch((error) => {
displayInfo(" Error : " + error, data);
});
</script>
</body>
</html>
</script>
Typical Syntax Call
<script type="text/javascript">
let URL = 'https://xxx.xxx.xxx.xxx/service.php'
let sPlugin = "plugin";
//
const data = { "configuration": [sPlugin, "action", "extra"],
'word': ' Απόδειξη ',
};
//
fetch(URL, { method: "POST", body: JSON.stringify(data),
headers: { "Content-type": "application/json;
charset=UTF-8"
}
}).then(response => response.json())
.then(dataRet => {
const returnJSON = JSON.parse(dataRet);
// returnJSON
// ....
///
})
.catch((error) => {
displayInfo(" Error : " + error, data);
});
</script>