onChange to Ajax Return Value
發表於 : 2016-12-06 20:19:04
form.php
ajax.php
代碼: 選擇全部
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>test</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</head>
<body>
input<input type='text' name='input01' id='input01' onChange='input01change(this.value)' size='20'>
<br>
return<input type='text' name='return01' id='return01' readonly size='20'>
<script>
function input01change(session) {
$.ajax({
url: 'ajax.php',
type: 'GET',
data: {k : session},
success: function( output ) {
console.log("Ajax Send "+ session);
console.log("Ajax Return Data "+ output);
$("#return01").val(output);
}
});
}
</script>
</body>
代碼: 選擇全部
<?php
$dsn = "mysql:host=localhost;dbname=test";
$db = new PDO($dsn, 'root', 'password');
$rs = $db->query("SELECT * FROM c_zipcode where id = '".$_GET['k']."' ");
$row = $rs->fetch();
echo $row['name'];