javascript - JSON encoding with Services_JSON and json_encode in PHP returning empty object with jQuery ajax call -
$.ajax({ url: '/ajax/get_rule.php', datatype: 'json', data: { feature : feature, ajax : 1 }, success: function(resp) { console.log('in here'); console.log('response: ' + resp); }, error : function() { console.log('there error...'); } });
i using php pear services_json class encode array json string , echo out in response, this:
echo registry('json')->encode(array('ajax' => 1, 'feature' => 'rfc1872')); exit;
in above example registry('json')
services_json
object.
i have tried php built-in function json_encode
:
echo json_encode(array('ajax' => 1, 'feature' => 'rfc1872')); exit;
neither of these work , although don't fall error callback in jquery ajax call above response value of response: [object object]
empty object in firebug.
why not receive response jquery code json-encoded string?
as felix king has provided in comment above caused by, effectively, casting resp
string with:
console.log('response: ' + resp)
changing to:
console.log(resp);
solved problem.
Comments
Post a Comment