Javascript 使用AJAX将数据从PHP传回HTML

Javascript 使用AJAX将数据从PHP传回HTML,javascript,php,jquery,html,ajax,Javascript,Php,Jquery,Html,Ajax,目前,我正在编写一个允许用户登录的登录表单。成功登录后,用户的用户名将显示在HTML中。但是,我不知道怎么做 PHP $username = $Row['username']; mysqli_free_result($Result); mysqli_close($Link); echo json_encode(array('success'=>'true','action'=>'login', 'username'=>$username, 'console.log'=>

目前,我正在编写一个允许用户登录的登录表单。成功登录后,用户的用户名将显示在HTML中。但是,我不知道怎么做

PHP

$username = $Row['username'];
mysqli_free_result($Result);
mysqli_close($Link);
echo json_encode(array('success'=>'true','action'=>'login',  'username'=>$username, 'console.log'=>$Query));
AJAX

success: function(data) {
console.log('controller sent data to the model');
console.log(data);
//data from JSON Array
if (data.action === "login") {
    window.location = https://n3228691.scm.tees.ac.uk/Yii/MACC/dashboard.html"; }
Dashboard.html

(我不知道如何编辑此网页)


为您的帮助干杯。

$('result_div').html(data.username)@Arno,你是说把这个代码放到我的dashboard.html中?这只是示例代码,不要直接复制/粘贴它。如果您在成功回调中添加了这样的功能,您可以编辑一个元素并显示用户名。@Arno抱歉,我不确定是否能理解您的意思,因为我是一个使用PHP的初学者,请参见以下JSFIDLE示例: