javascript - decoding the response from $.post -
this javascript
<script> function checkemail(email) { $.post('<?=base_url()?>checkemail',{ emailid : $('#inputemailid').val() },function(d){ cc = eval(d); alert(cc); }); } </script>
part of php file contains
if ($parts) { //these details exist $obj->status = 'yes'; } else { $obj->status = 'uni'; } $res[] = $obj;
when print_r($res)
status=>'yes'
but when alert(cc)
in javascript
function array() { [native code] }
how alert status
in javascript?
as mentioned in comments php
part should include call json_encode
if ($parts) { //these details exist $obj->status = 'yes'; } else { $obj->status = 'uni'; } // sending out $res should // can add proper json headers if content not formatted header('content-type: application/json'); print json_encode($obj);
your javascript should this
function checkemail(email) { $.post('<?=base_url()?>checkemail',{ emailid : $('#inputemailid').val() },function(d){ alert(d.status); }); }
Comments
Post a Comment