我正在尝试使用ajax从我的数据库中获取字符串,回显整个字符串,然后将字符串分成两半,并将其转换为语音。除了一步,我已经完成了每一步。我从我的数据库中获取了完整的字符串,并成功将其分成两半。这是我遇到麻烦的最后一步:
我遇到麻烦的部分
echo "
<script type = 'text/javascript'>
var msg = new SpeechSynthesisUtterance('$partOfString');
window.speechSynthesis.speak(msg);
</script>
";
?>
test1.php
<script type = "text/javascript">
function ajaxPass(gotoUrl,input,output) {
$.ajax({
type: "POST",
url: gotoUrl,
data: { input : input },
error: function(xhr,status,error){alert(error);},
success:function(data) {
document.getElementById( output ).innerHTML = data;
}
});
}
</script>
<input type = "button" value = "Click me" onclick = "ajaxPass('test2.php','Hello','output')">
<div id = 'output'> </div>
test2.php
<?php
$text = $_POST['input'];
//Use $text to get a string from database
echo $text; //echo the string we get from database
$partOfString //split the string in half and store in partOfString
echo "
<script type = 'text/javascript'>
var msg = new SpeechSynthesisUtterance('$partOfString');
window.speechSynthesis.speak(msg);
</script>
";
?>