php echo not working as expected -


the following code not working expected, echo statement never return response client side , hang.

        $query = "insert tasks (projectid,title,start,end,percentcomplete,parentid,orderid,summary,expanded,lastupdate)         values($project_id, '$title','$start','$end','$percentcomplete',$parentid,'$orderid','$summary','$expanded',now())";         $result = mysqli_query($con, $query);          if ($result) {             $last_id = mysqli_insert_id($con);             echo json_encode(array(id => $last_id, title => $title, start => $start, end => $end, percentcomplete => $percentcomplete));         } 

however, if added 1 more line of echo follows, both echo statement able received on client side.

        $query = "insert tasks (projectid,title,start,end,percentcomplete,parentid,orderid,summary,expanded,lastupdate)         values($project_id, '$title','$start','$end','$percentcomplete',$parentid,'$orderid','$summary','$expanded',now())";         $result = mysqli_query($con, $query);          if ($result) {             $last_id = mysqli_insert_id($con);             echo json_encode(array(id => $last_id, title => $title, start => $start, end => $end, percentcomplete => $percentcomplete));             echo 1;         } 

i cannot figure out wrong here, please advice on this. thanks

try setting output headers in controller (before output sent i.e. before json_encode):

$this->output->set_header('content-type: application/json; charset=utf-8');

and mentioned in earlier answer, use quotes around array keys.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -