Ich benutze Ajax jquery und PHP für mein Programm. Ich möchte jedes Wort, das ich in das Textfeld wie folgt aussehen Typ anzuzeigen:AJAX update jede Eingabe auf Textfeld Wortzähler
wenn ich getippt „Dies ist ein Beispielprobe Wort Wort Wort“, sollte die Ausgabe wie:
//output
This = 1
is = 2
a = 1
sample = 2
word = 3
//end_output
Mein aktueller Code zeigt nur, was ich in das Textfeld eingegeben habe und gibt es zurück. index.html
<!DOCTYPE html>
<html>
<head>
<title>Working with Javascript</title>
<script type="text/javascript" src="js/jquery-3.2.1.min.js">
</script>
</head>
<body>
<input type="text" name="input" id="textInput" autofocus/>
<div id="content"></div>
</body>
<script type="text/javascript">
var textInput = document.getElementById("textInput");
var jTextInput = $("#textInput");
var divSelector = document.getElementById("content");
textInput.onkeyup = function() {
console.log($("#textInput").val());
$.ajax({
"method": "POST", //to specify what type of METHOD to
REQUEST in the SERVER (GET or POST)
"url": "assigned.php", // where to send the request
"dataType": "JSON", // datatype of the request
"data": {
"text": $("#textInput").val()
}, //DATA values that you'll sebd
success: function (res) {
$("#content").html(res.reversedString);
}
});
};
</script>
</html>
und die andere Seite ist assigned.php
<?php
$var = array("reversedString" => $_POST['text']);
echo json_encode($var);
?>
ich eine Idee für PHP haben und es so aussehen
$text = $_POST['input'];
$words = explode(' ', $text);
sort($words);
$result = array_combine($words, array_fill(0, count($words), 0));
$len = count($words);
for ($i = 0; $i < $len; $i++) {
echo $words[$i] . " ";
}echo "<br> <br>";
foreach ($words as $word) {
$result[$word] ++;
}
foreach ($result as $word => $count) {
echo "$word = $count<br>";
}
aber ich habe keine Ahnung, wo um es zu sagen und wie wird es funktionieren und ob es funktioniert oder nicht. Ich ziehe es vor, es auf die assigned.php zu setzen. Danke für Ihre Hilfe :)
Vielen Dank für die Information mate. Ich verstehe nicht ganz, was du meinst, denn ich bin neu in der Ajax, aber eine Geige wird sehr geschätzt. –