I'm building an application online with the use of containers. The index.php displays the app and the URL's link to the containers that have php code which perform actions upon requests from the index page. I'm wondering why my xttp.open requests are not returning any values once they are sent. Am i missing something in my code?
index.php
function CountWords() {
if (result == 1)
result = 'The total word count is +';
else
result = 'Total word count = 0 ';
document.getElementById('display-1').value = result;
}
function WordCount() {
paragraph = document.getElementById('paragraph').value
if (paragraph == '')
return;
else {
let xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var j = JSON.parse(this.response);
result = j.answer;
CountWords();
}
};
xhttp.open("GET", countURL + "?paragraph=" + paragraph);
xhttp.send();
return;
}
}
URL container that the request is sent to:
<?php
header("Access-Control-Allow-Origin: *");
header("Content-type: application/json");
require('functions.php');
$paragraph = $_REQUEST['paragraph'];
$answer = wordCount($paragraph);
$output['answer']=$answer;
echo json_encode($output);
exit();
Aucun commentaire:
Enregistrer un commentaire