Cés*_*arQ -2 html javascript php post input
我创建了按钮:
<input type = "text" name="consulta" size = "12" value = "565656" id = "consulta" />
<input type="button" value = "Pesquisar" onclick="jawa()" />
Run Code Online (Sandbox Code Playgroud)
而jawa()函数是:
function jawa(){
var fieldNameElement = document.getElementById('pesquisa');
//just for test if JS takes values....
resultado = consulta.value;
escolha = cbox.value;
fieldNameElement.innerHTML = "<?echoo();?>";
}
Run Code Online (Sandbox Code Playgroud)
和php中的echoo()...
<?
function echoo(){
if (isset($_POST['consulta'])) {
$con = $_POST['consulta'];
}else{
$con = "not working";
}
$conexao =mysql_pconnect("localhost:3306","xxx","xxx");
mysql_select_db("...",$conexao);
$str_chamado = "Select *
From
`...`.`...`
Where
`NU_TELEFONE`='$con'";
... ?>
Run Code Online (Sandbox Code Playgroud)
它说"Undefined index:consulta"我无法从输入中获取文本,它可以是什么?
你不能从Javascript调用PHP函数,因为PHP在页面显示之前被解释,之后无法与之交互.
你可以使用Ajax实现这一点,或者发送表单并使用PHP和输出处理任何你想要的值.