<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
function getvalues() {
var selname = $("input[name='names']:text").val();
$.ajax({
url: "process.php",
data: {
"selname": selname
},
type: 'post',
dataType: "json",
success: function (output) {
console.log(output);
$("#aic").val(output[0]);
$("#batchcode").val(output[1]);
}
});
}
</script>
</script>
</head>
<body>
<form method="post">
<input type="text" name="names" id="query" onblur="getvalues()" />
<input type="text" name="aic" id="aic" />
<textarea name="batchcode" id="batchcode" rows="4" cols="50"></textarea>
</form>
</body>
</html>
process.php
<?php
if(isset($_POST['selname']))
{
$response = array('0001', 'short info : john 29 years old - technician '); // add return data to an array
echo json_encode($response); // json encode that array
exit;
}
?>
当我在
input type="text" name="names"
上键入内容时我输入的是文本
"aic" >>> 1;
,但是在textarea中却没有得到"short info : john 29 years old - technician "
,请告诉我错误在哪里! 最佳答案
将json转换为数组