Reputation: 553
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
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
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