Display AJAX response from PHP I have used jQuery AJAX for my development. Below I have added example code for AJAX request and response. 

ajax.php

$queView = array();

$queView['time'] = 40;
$queView['name'] = "Level hard";
$queView ['noQuestions'] = 10;
$queView['queDetails'] .= "&lt;h1&gt;Some html content&lt;/h1&gt;";
$queView['queDetails'] .= "&lt;img src='root/imag/imag.jpg' /&gt;";


foreach($users as $user){
   $queView['queDetails'] .= "&lt;p&gt;".$user['name']."&lt;/p&gt;";
   $queView['queDetails'] .=  "&lt;p&gt;".$user['address']."&lt;/p&gt;"; 
}

echo json_encode($queView);


JavaScript function with jQuery;

function showQuestions(){

 $.ajax({
        data:{showQues:'1',attemptedQue:queId,selAnswer:checkedAns,timeTaken:timeTaken},
        url:'include/ajaxAttempt.php',
        success: function(data){

            data = $.parseJSON(data);

            $('#time').html(data.time);
            $('#name').html(data.name);
            $('#noQuesitons').html(data.noQuestions);
            $('#queDetails').html(data.queDetails);
        },

        error:function(xhr,err){
            alert("Error");
        }
    });    
}


$queView['queDetails'] has a lot of HTML content.

Is this a good practice?
If you're passing information, pass only information, not markup. Alternatively completely generate the HTML markup on the server-side, and just apply it on the client side. There's no point in combining the two, and if done wrong you could cause double escaping issues.

Second, don't use alert() as a debug function. Use console.log() and use your console.