php - ajax call on CodeIgniter page returns result "an empty string" -
php - ajax call on CodeIgniter page returns result "an empty string" -
i've got ajax script in index.php of ci application. trying homecoming simple string @ point testing. i'm using next code this:
<script> $(document).ready(function() { $.ajax({ type: 'post', url: 'index.php/loader/opc_client', datatype: 'json', cache: false, success: function(data) { console.log(data); $('#opc-results').html(data.test); } }); }); </script> the url in phone call standalone file it's own controller. when access file straight in browser it's loaded , returns expected results. next php code:
<?php echo json_encode("test"); ?> i can see post results in firebug after function fired firebug window displays "an empty string" under post in console view.
any clues? i'm not understand this...
update: if console.log('success') in success parameter of ajax call, logs reason data empty
you shouldn't json_encode string although technically php can deal string array guess in case things weird. wrap in array, , when youre done testing you'll improve off using key value pairs makes thing on client side easier deal with, ie obj.property.
try echo json_encode(arrray('test'));
php jquery ajax codeigniter
Comments
Post a Comment