【发布时间】:2011-07-06 15:42:28
【问题描述】:
我正在使用:echo json_encode($Response);将关联数组发送回 JQuery Ajax。每当我尝试读取每个 ID 键值时,我都会得到一个未定义的值。请帮我弄清楚我做错了什么......提前谢谢
我的 PHP 代码:
$Stuff = 'Hello world';
$Success = true;
$Content = $Stuff;
$Response = array('Success' => $Success, 'Content' => $Content);
echo json_encode($Response);
#
#
我的 JS 代码:
var sFirstName = $('#student_first_name').attr('value');
$.ajax({
type: "GET",
url: "../pgs/UpdateEditAStudent.php",
data: "FirstName="+ sFirstName ,
//The below code will give me: {"Success":true,"Content":"Hello world"}
success: function(data){$("#Ajax_response").html(data);}
//The popup window will show me "Undefined"
//and: {"Success":true,"Content":"Hello world"}
success: function(data){$("#Ajax_response").html(data); alert(data.Content);}
});
【问题讨论】: