tracer tong
tracer tong

Reputation: 553

Ajax / Json result is returned but does not display

I have the following JQuery AJAX call. When the the output variable is alerted everything looks fine, but I cannot display individual elements successfully. Can anyone see why?

JQUERY

$('#test_load').click (function () {
    //ajax callbacks
    $.get('js/request.php?p=template&t=<?php  echo $_SESSION['user']['ajax_token']; ?>&a=content|content', function (output){
        //alert (output);
        if (output.error) {$('#test_content').html(output.error);} else {$('#test_content').html(output.result);} 
    });
return false;
});

HTML

<div class="one_col">

<div id="test_content">
<?php //print_r($output['r']); ?>
</div>
<a href="#" id="test_load">Test pattern</a>

</div>

Upvotes: 0

Views: 64

Answers (2)

Rohan Kumar
Rohan Kumar

Reputation: 40639

Use dataType as json Refer http://api.jquery.com/jQuery.get/

 $('#test_load').click (function () {
    //ajax callbacks
    $.get('js/request.php?p=template&t=<?php  echo $_SESSION['user']['ajax_token']; ?>&a=content|content', function (output){
        //alert (output);
        if (output.error) {$('#test_content').html(output.error);} else {$('#test_content').html(output.result);} 
    },'json');
return false;
});

Upvotes: 0

pwolaq
pwolaq

Reputation: 6381

the problem is that you haven't specified the type of data that you want to receive, try this:

$('#test_load').click (function () {
    $.get('js/request.php?p=template&t=<?php  echo $_SESSION['user']['ajax_token']; ?>&a=content|content', function (output){
        if (output.error) {$('#test_content').html(output.error);} else {$('#test_content').html(output.result);} 
    }, "json");
return false;
});

notice the "json" parameter at the end of the function

Upvotes: 1

Related Questions