CodeIgniter Forums

Full Version: JSON won't print individual value
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]jvk22[/eluser]
I am running a jquery ajax function to get JSON data, the data is returned properly, but when I go to display it, the variable shows up undefined.

Code:
public function ajax_add_new_task()
{
  $b ='';
  $b .= '<table>';
  $b .= '<tr><td>Task Title:</td><td>&lt;input type="text" name="title" id="title"&gt;&lt;/td></tr>';
  $b .= '</table>';
  
  $result['success'] = TRUE;
  $result['message'] = $b;
  
  echo json_encode( $result);
}
}

Code:
function show_add_task()
{
  $.ajax({
             type: "POST",
             url: "tasks/ajax_add_new_task",
             data: {
              'submit':'submit',
              },
             datatype:'json',
             success: function(msg) {
              alert(msg.message);
     $(".add_task").html(msg.message);

             }
         });
}