我想要json的第一个元素。但是使用data.first我什么也没得到。尽管alert(data)打印完整的json字符串,请帮帮我
<?php
include_once '../con_db.php';
$rf = $_POST['rf'];
$rid = $_POST['tid'];
$data = array("first" => "one","seconed"=> "two");
echo json_encode($data);
?>
下面是ajax请求的jquery代码
$('.fbased').focusin(function(){
var rf = $(this).attr('id');
var tid = $("#test_id").val();
$.ajax({
type:'POST',
url:'functions/ftable.php',
data: 'rf='+rf+'&tid='+tid,
datatype: "json",
success : function(data){
$("#"+rf).val(data);
}
});
});
最佳答案
success : function(data){
var parsed = JSON.parse(data);
$("#"+rf).val(parsed.first);
}