Php 使用AJAX功能更改Submit按钮,以立即响应输入
我想将以这种形式获得输入值答案的可能性(提供数字的俄语单词)从submit按钮更改为动态AJAX函数,以便立即获得答案 谢谢你 在@user1978142的帮助下,它可以完美地工作。 但现在我搜索一个解决方案,添加一个播放按钮,用谷歌TTS(文本到语音)拼写单词 我为谷歌TTS找到了一个解决方案,但它只适用于谷歌ChromePhp 使用AJAX功能更改Submit按钮,以立即响应输入,php,jquery,ajax,dynamic,onchange,Php,Jquery,Ajax,Dynamic,Onchange,我想将以这种形式获得输入值答案的可能性(提供数字的俄语单词)从submit按钮更改为动态AJAX函数,以便立即获得答案 谢谢你 在@user1978142的帮助下,它可以完美地工作。 但现在我搜索一个解决方案,添加一个播放按钮,用谷歌TTS(文本到语音)拼写单词 我为谷歌TTS找到了一个解决方案,但它只适用于谷歌Chrome <? $ru = new NumberFormatter("ru", NumberFormatter::SPELLOUT); ?> &l
<?
$ru = new NumberFormatter("ru", NumberFormatter::SPELLOUT);
?>
<form method="get" action="index.php">
Zahl:
<input name="zahl" type="text" size="15" maxlength="15">
<input type="submit" value="Anzeigen">
</form>
<?
if (is_numeric($_REQUEST['zahl'])) echo $ru->format($_REQUEST['zahl']);
?>
扎尔:
由于jQuery被标记,并且已经安装了NumberFormatter
,所以您只需要一个简单的$。ajax
。还要注意编码(我认为ru
是俄语的意思)。考虑这个例子:
您的index.php
<form method="POST" action="index.php">
<label for="zahl">Zahl:</label> <br/>
<input id="zahl" name="zahl" type="number" size="15" maxlength="15"><br/><br/>
<div id="results" style="width: 400px;"></div> <!-- results appear here -->
</form>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#zahl').on('keyup', function(){
// ajax request server
$.ajax({ url: 'number_process.php', type: 'POST', dataType: 'text', data: {value: $(this).val()},
success: function(response) {
$('#results').text(response); // append to result div
}
});
});
});
</script>
扎尔:
$(文档).ready(函数(){
$('#zahl')。on('keyup',function(){
//ajax请求服务器
$.ajax({url:'number_process.php',type:'POST',dataType:'text',data:{value:$(this).val()},
成功:功能(响应){
$('#results').text(response);//追加到result div
}
});
});
});
number\u process.php(示例名称)
创建处理ajax请求的php文件。这将处理它并返回您的值
<?php
if(isset($_POST['value'])) {
$ru = new NumberFormatter("ru", NumberFormatter::SPELLOUT);
// normal processing
$value = $ru->format($_POST['value']);
echo mb_convert_encoding($value, 'UTF-8', 'auto'); // russian characters
exit;
}
?>